The httpservletrequest class includes both the getattribute () method and the getparameter () method. The two methods have the following differences:
(1) The httpservletrequest class has the setattribute () method instead of the setparameter () method.
(2) When two Web components are linked, the linked component obtains the request parameters through the getparameter () method, for example, assuming welcome. JSP and authenticate. JSP is a link, welcome. JSP has the following code:
<A href = "/authenticate. jsp? Username = weiqin "> authenticate. jsp </a>
Or:
<Form name = "form1" method = "Post" Action = "authenticate. jsp">
Enter the User name: <input type = "text" name = "username">
<Input type = "Submit" name = "Submit" value = "Submit">
</Form>
In authenticate. jsp, the request parameter username is obtained through the request. getparameter ("username") method:
<% String username = request. getparameter ("username"); %>
(3) When the forwarding relationship is between two Web components, the forwarding target component shares the data within the request range with the conversion source component through the getattribute () method. Assume that the relationship between authenticate. jsp and hello. jsp is forwarding. Authenticate. jsp wants to pass the current username to hello. jsp. How can this data be transmitted? First, call the setattribute () method in authenticate. jsp:
<%
String username = request. getparameter ("username ");
Request. setattribute ("username", username );
%>
<JSP: Forward page = "Hello. jsp"/>
In hello. jsp, use the getattribute () method to obtain the username:
<% String username = (string) request. getattribute ("username"); %>
Hello: <% = username %>
From a deeper perspective, the data transmitted by the request. getparameter () method is transmitted from the Web Client to the Web server, representing the HTTP request data. The request. getparameter () method returns string-type data.
The data transmitted by the request. setattribute () and getattribute () methods only exists in the Web Container and is shared among the Web Components with forwarding relationships. These two methods can be used to set object-type shared data.