Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Frame JSP file

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to use Frame JSP files for you. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

When using Forward (), Servlet engine passes the HTTP request from the current Servlet or JSP to another Servlet,JSP or ordinary HTML file, that is, your form is submitted to a.JSP, and Forward () is redirected to b.JSP in a.JSP. At this time, all the information submitted by form can be obtained in b.JSP, and the parameters are automatically passed. But Forward () cannot be redirected to a Frame JSP file, it can be redirected to a html file with frame, while Forward () cannot be passed with parameters, such as Servlet?name=frank, so it can be transferred to the next page through response.setAttribute ("name", name) within the program. The browser address bar URL remains unchanged after redirection.

Example: redirect in Servlet

Public void doPost (HttpServletRequest request,HttpServletResponse response)

Throws ServletException,IOException

{

Response.setContentType ("text/html; charset=gb2312")

ServletContext sc = getServletContext ()

RequestDispatcher rd = null

Rd = sc.getRequestDispatcher ("/ index.jsp"); / / directed page

Rd.forward (request, response)

}

It is commonly used in Servlet, not in JSP.

Response.sendRedirect ()

To work on the user's browser, sendRedirect () can be passed with parameters, such as Servlet?name=frank to the next page, and it can be redirected to different hosts, and sendRedirect () can be redirected to Frame JSP files. After redirection, the URL of the redirected page appears on the browser address bar.

Example: redirect in Servlet

Public void doPost (HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {response.setContentType ("text/html; charset=gb2312"); response.sendRedirect ("/ index.jsp");}

Because response is an implicit object in a JSP page, you can use response.sendRedirect () to relocate directly in a JSP page.

Note:

(1) use response. When sendRedirect, you cannot have HTML output in front of it.

This is not absolute, no HTML output actually means that no HTML can be sent to the browser. In fact, today's server has a cache mechanism, usually at 8K (I mean JSPSERVER), which means that unless you turn off cache, or you use out.flush () to force refresh, then a small amount of HTML output is allowed before using sendRedirect.

(2) after response.sendRedirect, the sentence "return" should be followed.

We already know that response.sendRedirect redirects through the browser, so there is no actual action until the page is processed. Now that you're about to turn, what's the point of the later output? And it is possible that the steering will fail because of the later output.

Compare:

(1) Dispatcher.Forward () is the transfer of control in the container, and the redirected address will not be displayed in the client browser address bar.

(2) response.sendRedirect () is a complete jump, and the browser will get the address of the jump and resend the request link. In this way, the jumped link address can be seen from the browser's address bar.

The former is more efficient, and the RequestDispatcher.Forward () method is used as much as possible when the former meets the needs.

Note: in some cases, for example, if you need to jump to a resource on another server, you must use the HttpServletResponse.sendRequest () method.

This is the end of the article on "how to use Frame JSP files". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report