One, Request.getparameter () and Request.getattribute () difference
(1) Request.getparameter () is obtained through the implementation of the container to obtain the data via similar post,get, Request.setattribute () and getattribute () is only inside the Web container flow, Only the request processing phase.
(2) The data passed by the Request.getparameter () method is uploaded from the Web client to the Web server side and represents the HTTP request data. The Request.getparameter () method returns data of type String.
The data passed by the Request.setattribute () and GetAttribute () methods will only exist inside the Web container
Another point is that the HttpServletRequest class has a setattribute () method and no Setparameter () method.
Take an example, if two Web pages are linked, that is, if you want to link to 2.jsp from 1.jsp, the link is 2.jsp can get the request parameters through the GetParameter () method.
If there is a 1.jsp in
<form name="Form1"Method="Post"action="2.jsp">Please enter user name:<input type="text"Name="username"><input type="Submit"Name="Submit"Value="Submit"></form>
In 2.jsp, the Request.getparameter ("username") method is used to obtain the request parameter username:
<% String Username=request.getparameter ("username"); %>
However, if the two Web is a forwarding relationship, the forwarding destination Web can use the GetAttribute () method to share data in the request scope with the source web, or an example.
With 1.jsp and 2.jsp
1.jsp want to pass the current user name to 2.jsp, how to pass this data? First call the following setattribute () method in 1.jsp:
<%String username=request.getparameter ("username"); Request.setattribute ("username", username); %><jsp:forward page="2.jsp" /> in 2.jsp by the GetAttribute () method to obtain the user name: <% string Username= (String) request.getattribute ("username"); %>
Ii. Request.getattribute () and Request.setattribute ()
Request.getattribute ("Nameofobj") can get the value of a control in a form on a JSP page. In fact, the name and value of object in the form control are stored in a hash table, so the name of object is given here to the hash table to find the value corresponding to it.
When using Request.setattribute (position, nameofobj) for different page values, only one pass from a.jsp to b.jsp, and then this request loses its scope, and then it will be set up again. Request.setattribute (). The use of Session.setattribute () always retains this value in a process.
P.s.:javascript and JSPs cannot pass values to each other because JavaScript runs on the client and the JSP runs on the server side. If you want to allow parameters to be passed between them, you can set up a hidden control in the JSP and use its value in conjunction with the above mentioned usage to pass the desired value.
Request Property Request.getattribute ()