Sunday, July 25, 2010

On the JSP page Jump and forward the request



JSP page forwards the request collection Jump

1, response.sendRedirect (url)

The request is redirected, the parameters of the original page is not here, that use request.getParameter ("param") returns null

2, forward the request forwarding, refer to the original page request, response objects passed a new page, so this page has the same old request, response object. This request.getParameter ("param") to the corresponding values can be

3, distinguish ServletContext.getRequestDispatcher and ServletRequest.getRequestDispatcher

ServletContext.getRequestDispatcher relative context path must be the absolute path

ServletRequest.getRequestDispatcher may be a relative can also be absolutely

4, attention is this: After using the forward forward to see in the browser address bar shows is not transmitted before forwarding the post. If the test.jsp to good.jsp forward, then the address bar shows test.jsp. This is because the forward was carried out on the server side, the browser did not know, but redirection is carried out in the client, so Use response.sentRedirect ("red.jsp") will be directly directed to red.jsp. And that brings me index.jsp servlet if the request is then carried out forawrd servlet forward to another red.jsp page, but view the results, in the address bar displays the name of the servlet that will only rather than red.jsp, if you want to know the name of the final page to see that only the search code.

reference it:

Server-side to turn the four kinds of methods:

1. ServletContext of getRequestDispatcher ()

2. ServletContext of getNamedDispatcher ()

3. ServletRequest of getRequestDispatcher ()

4. ServletResponse of sendRedirect () to turn.

1.2.3 => forward () 4. SendRedirect ()

Using the forward method because it more efficient. Only way forward can not be used (for example, to turn to a non web application), then use ServletResponse the sendRedirect () method.

Comparison with sendRedirect

Although sendRedirect methods can browse the web browser, redirect to another page, but the two are not the same in principle.

a.: Action is to use server-side, the data output to the buffer mechanism, the previous page is still output to the client before the cancellation of the output data, and then output the data to another Web page, to redirect the browser effect.

Advantages: two pages within the object request can be shared between the variables.

b. sendRedirect: action through the HTTP protocol Header, redirect the browser to issue commands, therefore, does not involve the issue to the server-side buffer.

However, as sendRedirect method acting on the client, so redirect there around the page can not share the variables in the request object.

Solution: response.sendRedirect ("sendRedirect.htm? Name = sparkwu & E-Mail = spark.wu @ cobra-tech.com")







Recommended links:



Photoshop effect of creating non-mainstream MTV



Ninetowns Submitted To The U.S. SEC Annual Report FY08 Net Profit Down 72% Correction



Graphics come from paint in



Foxconn Jumped Reproduction Of A Female Employee Jumped 7th Floor



News SERVERS Specialist



Correct UNDERSTANDING of the importance of examinations and the usual accumulation of [2]



Compare Themes And Wallpaper



Response To Illegal Cash Payments, Said Bao Claimed "seriously Inaccurate Information"



Dvd Audio Ripper



Rm To Avi



CHINA IPTV-What is the short board?



convert 3GP to mp4



Games Arcade evaluation



BPR Get To The Root



Aac files



Comprehensive understanding of redirection 301



No comments:

Post a Comment