1. scenario demonstrates
Now there is a demand: the request reached the server, the server needs the requested data to another page, how to achieve?
2. Objectives Analysis
Jump to page through the server, implemented in two ways: one is forwarding a redirect.
We know that can carry forward the data, redirect and can not carry data, so, in order to carry data jump page, must be forwarded to achieve.
3. Solution
Page value by the getAttribute (); by setAttribute () value is passed to the page request object.
Request address
http://localhost:8070/demo2/dispatcher.do?userName=%25E7%2594%25A8%25E6%2588%25B7%25E5%2590%258D&password=pwd
// tells the browser to utf-8 character set to resolve success.jsp response.setCharacterEncoding ( "utf-8"); // username String userName = request.getParameter ( "userName"); // Tomcat server, automatic decoding time, there need to decode one (userName total encoded twice) userName = URLDecoder.decode (userName, "UTF-8"); // password String = request.getParameter password ( "password"); // forward What to bring when page data request.setAttribute ( "userName", userName); request.setAttribute ( "password", password); // Jump to success.jsp (browser's address bar does not change) request.getRequestDispatcher ( "/success.jsp").forward(request, response);
The value of a page in two ways:
1. expression obtained by the EL;
$ {Name} properties
2. Get through a small script.
<% = Request.getAttribute ( "attribute name")%>
4. Effects show
Description:
Page by means of the value of the request object, can only be achieved in the jsp, because: a servlet jsp nature, and belongs to the servlet java language, so you can use jsp direct request object, and then be able to value.
Accordingly, if you are forwarding a html file, then sorry, you will not be able to get the data request objects carried.
Written in the last
Which big brother If it is found there is leakage of the carelessness of the article or need to add more content, welcome message! ! !
related suggestion: