1. Different values are obtained
- GetAttribute represents a property that is set from the request scope and must be set through setattribute to be obtained through getattribute. Both the set and the obtained values are of type object.
- GetParameter is the parameter that receives the page submission, mainly has the form submits the parameter, the URL overrides passes the parameter (the ID value in the http://item.jsp?id=1) and so on, therefore does not need through the Setparameter to set the parameter, And the return type of the parameter is a string type.
2. Data transfer paths are different
- The Request.getparameter () method passes data from the Web client to the Web service side, which represents the HTTP request data used for form or URL redirection.
Example:
For example, the conversion between two Web pages, exactly two Web pages when the link relationship, from login.jsp link to menu.jsp, menu.jsp can pass the getparameter() method to obtain the request parameters.
LOGIN.JSP:
1 <% 2// get parameter 3 String username=request.getparameter ("username" ); 4 // Setting Properties 5 Request.setattribute ("username", username); 6 %> 7 8 <!--page Jump--! >9 <jsp:forward page= " Menu.jsp "/>
1 <form name= "Form1" method= "Post" action= "menu.jsp" > 2 Please enter user name: <input type= "text" name= "username" >< C1/>3 <input type= "Submit" name= "Submit" value= "Submission" > 4 </form>
The request.getparameter ("username") method can be used to obtain the requested parameter username in menu.jsp:
1 <% String username=request.getparameter ("username"); %>
- The data passed by Request.getattribute () exists only within the Web container, within the request scope, which is the sharing between Web components when forwarding.
Example:
Login.jsp want to pass the current user name to menu.jsp, first call the SetAttribute() method in login.jsp:
1 <% 2// get parameter 3 String username=request.getparameter ("username"); 4// Set Properties 5 Request.setattribute ("username", username); 6%> 7 8 <!--page Jump--! >9 <jsp:forward page= "menu.jsp"/>
Get the user name in menu.jsp by the getattribute() method:
The difference between "getattribute" and "GetParameter" in Servlet HttpRequest