Sometimes you also need to pass parameters between multiple JSP pages. The following describes the implementation methods.
(1) Add
For example, <ahref = "thexuan. jsp? Action = transparams & detail = directe "> directly passing parameters </a>
When using response. sendredirect for page redirection, you can also use the following code:
Response. sendredirect ("thexuan. jsp? Action = transparams & detail = directe "), which can be obtained by request. getparameter (name ).
(2) JSP: Param
It allows you to pass parameters to the include page on the home page, as follows:
<JSP: Include page = "relativeurl"> <JSP: paramname = "Param name" value = "paramvalue"/> </jsp: Include> you can also use JSP: when the forward action performs a page Jump, the parameters are passed as follows:
<JSP: Forward page = "relativeurl"> <JSP: paramname = "paramname" value = "paramvalue"/> </jsp: forward> This method is the same as a common form parameter, or through request. getparameter (name) gets the Parameter
(3) set the session and request
The displayed parameters are placed in the session and request to pass the parameters.
Session. setattribute (name, value); Request. setattribute (name, value) parameters:
Value = (valueclassname) session. getattribute (name); value = (value classname) request. getattribute (name); you must have noticed that the type conversion is performed when the parameter is obtained, because the attributes of the objects placed in the session and request are treated as Java. lang. if the object type is not converted, The classcastexception exception is reported when the value is directly paid.
Passing parameters between multiple JSP pages
1. How to pass parameters between multiple JSP pages? Use the JSP built-in scope object session. Using its two methods setattribute (), getattribute ()
2. The following example implements the function of passing parameters of the first JSP page to the third page.
3. The Code is as follows: 1.jsp
<HTML> <form method = getaction = 2.jsp> what's yourname <input type = text name = username> <input type = submitvalue = submit> </form>
<HTML> <form method = postaction = "3.jsp? Pass = 11 "> <% stringname = request. getparameter ("username"); Session. setattribute ("username", name); %> your name is: <% = request. getparameter ("username") %>
<Br> what's your holobby <inputtype = text name = holobby> <inputtype = submit value = submit> </form>
<HTML> your name is: <% = session. getattribute ("username") %> <br> your holobby is: <% = request. getparameter ("holobby") %> <br> your password is: <% = request. getparameter ("pass") %> <br> </form>