欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Forward versus redirect

A Controller servlet may perform either a forward or a redirect operation at the end of processing a request. It is important to understand the difference between these two cases, in particular with respect to browser reloads of web pages.

Forward

  • a forward is performed internally by the application (servlet).
  • the browser is completely unaware that it has taken place, so its original URL remains intact
  • any browser reload of the resulting page will simple repeat the original request, with the original URL

Redirect

  • a redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original
  • a browser reload of the second URL will not repeat the original request, but will rather fetch the second URL
  • redirect is marginally slower than a forward, since it requires two browser requests, not one
  • objects placed in the original request scope are not available to the second request.

There are several ways to perform a Redirect, here are a few common ones:

  • URL Redirection (HTTP 301):
    HTTP/1.1 301 moved permanently    Location: http://www.example.org/
  • HTTP Refresh Header (Not Recommended)
    HTTP/1.1 200 ok    Refresh: 0; url=http://www.example.com/
  • HTML <meta /> tag
    <meta http-equiv="refresh" content="0; URL=http://www.example.org/" />
  • JavaScript (many possible solutions, generally not accessible or searchable)
    <script type="text/javascript">location.;</script>

In general, a forward should be used if the operation can be safely repeated upon a browser reload of the resulting web page; otherwise, redirect must be used. Typically, if the operation performs an edit on the datastore, then a redirect, not a forward, is required. This is simply to avoid the possibility of inadvertently duplicating an edit to the database.

More explicitly :

  • for SELECT operations, use a forward
  • for INSERT, UPDATE, or DELETE operations, use a redirect

In HTML, a <FORM> tag can either GET or POST its data. In this context, a GET corresponds to a SELECT-then-forward, and a POST corresponds to an edit-then-redirect.

It is strongly recommended that forms for the input of search criteria should use GET, while forms for editing database records should use POST.

SECURITY NOTE: When using GET, be sure to not expose sensitive data in the URL’s.

Example

This example is after the style of the WEB4J Controller class. The important methods of the Servlet API are :


import java.io.IOException;import javax.servlet.*;import javax.servlet.http.*;import hirondelle.web4j.action.Action;import hirondelle.web4j.action.ResponsePage;import hirondelle.web4j.request.RequestParser;import hirondelle.web4j.model.BadRequestException;public class RedirectForward extends HttpServlet {//..many items elided@Override public final void doGet(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException {processRequest(aRequest, aResponse);}@Override public final void doPost(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException {processRequest(aRequest, aResponse);}/*** Handle all HTTP <tt>GET</tt> and <tt>POST</tt> requests.*/protected void processRequest(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException {RequestParser requestParser = RequestParser.getInstance(aRequest, aResponse);try {Action action = requestParser.getWebAction();ResponsePage responsePage = action.execute();if ( responsePage.getIsRedirect() ) {redirect(responsePage, aResponse);}else {forward(responsePage, aRequest, aResponse);}}catch (BadRequestException ex){//..elided      //use Response.sendError()    }catch (Throwable ex) {//..elided      //use Response.sendError()    }}// PRIVATE //private void redirect(ResponsePage aDestinationPage, HttpServletResponse aResponse) throws IOException {String urlWithSessionID = aResponse.encodeRedirectURL(aDestinationPage.toString());aResponse.sendRedirect( urlWithSessionID );}private void forward(ResponsePage aResponsePage, HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException {RequestDispatcher dispatcher = aRequest.getRequestDispatcher(aResponsePage.toString());dispatcher.forward(aRequest, aResponse);}} 
 

getRequestDispatcher

RequestDispatcher getRequestDispatcher(String path)
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static.

The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root. This method returns null if the servlet container cannot return a RequestDispatcher.

The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a relative path.

 

Parameters:
path - a String specifying the pathname to the resource. If it is relative, it must be relative against the current servlet.
Returns:
a RequestDispatcher object that acts as a wrapper for the resource at the specified path, or null if the servlet container cannot return a RequestDispatcher
See Also:
RequestDispatcher, ServletContext.getRequestDispatcher(java.lang.String)
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
jsp/servlet中 forward, include, reDirect 之間的區別
轉發(fā)(forward)、包含(include)及轉向(redirect)的區別與聯(lián)系
getRequestDispatcher()與sendRedirect()的區別
forward和redirect的區別
java web開(kāi)發(fā)入門(mén)-request對象
jsp和servlet重定向
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久