GetParameter and getattribute differences in JSP

Source: Internet
Author: User

(2) When the two Web Components are link relationships, the linked component obtains the request parameters through the GetParameter () method.

(3) When a forwarding relationship is between two Web components, the forwarding target component shares the data in the request scope with the forwarding source component through the GetAttribute () method.

Typically use GetParameter for parameters passed on forms and links

Use Request.getattribute ("name") to assign values by Request.setattribute ("name", "Jerry")

This question is the difference between request and session, the request scope is smaller, just a petition, simply say that you are on the page an operation, Request.getparameter () is from the previous page in the URL, form to get parameters, But if a request involves more than one class, the parameters are taken later, Request.setattribute () and Request.getattribute () can be used, but when the result is output, the request ends.

The session can span many pages and can be understood as multiple requests from the client's same IE window. This can be passed between parameters, such as a lot of Web site user login is used.

GetParameter returns a string that reads the value from the submitted form; (page parameters and strings) such as? Id=123 or something like that.
GetAttribute return is an object, need to hold the conversion, can be set to setattribute to arbitrary things, using very mobile, can be used at any time; often used for servlet page pass parameters to JSP
GetParameter () is the parameter value that gets post/get conveyed;
--getattribute () is the data value in the object container;
--getparameter: Used for client redirection, that is, clicking on a link or submitting a button simultaneous value, which is used to suck data when using a form or URL redirection value.
--getattribute: When used with end multiplicity orientation, the forward function is utilized in Sevlet, or the mapping.findforward is used in struts. GetAttribute can only receive the value of the step passed by SetAttribute.
--getparameter () is the parameter value that gets post/get conveyed;
--getattribute () is the value that gets the session;
Other, you can use Setattribute,getattribute to send to absorb things. and GetParameter obviously can only pass strings.
SetAttribute is the application to put this thing in the corresponding piece of memory in the page, when your page is a pity to redirect to another page, the application Manager will copy the memory of the other page corresponding
In memory so getattribute can get the value you set, although this point can pass things. The session is the same, but the life cycle of things in memory is not the same.
GetParameter is just the app utility when you're explaining the text of the request page you've come up with, get the value you set on the form or URL redirection.

Personal Insights:

When the user passes the value as the link parameter to the next page or the serve, in fact, is to pass the data between the webpage, uses the Request.getparameter (): extracts sends the parameter such as: this page
http://community.csdn.net/expe/topic/4633/4633804.xml?temp=.3488123 request.getparameter ("temp") = = ". 3488123"

When the user places a value in the request in a property (Request.setattribute ("AA", "tt"), the "AA" attribute name can be arbitrarily taken), with the GetAttribute (attribute name).

The request range is smaller, just a petition, simply a single action on your page, and Request.getparameter () gets the parameters from the URL and form in the previous page. But if a request involves more than one class,
Parameters are later used, which can be Request.setattribute () and Request.getattribute (), but when the result is output, the request ends. Request.getparameter: is used to assume parameters from Get essentials or post essentials
<form method=post>
<form method=get>
<a href= "1.jsp?id=1" >ok</a>
can only serve as java.lang.string
That is to say string hotel_id = Request.getparameter ("hotel_id");
Request.getattribute
is used to act as a variable or action from a servlet (really action is a special servlet)
In action, Request.setattribute ("ret", ret);
can only serve as java.lang.object
It is also said list ret = (list) request.getattribute ("ret");
            If you only use JSP, the base is not Request.getattribute ()     request.getparameter (), Request.setattribute () The difference is as follows: (1) Request.getparameter () obtained through the implementation of the container to get through a similar post, Get incoming data, Request.setattribute () and getattribute () just flow inside the Web container, just 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 and there is a point where the HttpServletRequest class has a SetAttribute () method, Without the Setparameter () method. Take an example, if the two Web pages are linked, that is, to link to 2.jsp from 1.jsp, the link is 2.jsp can use the GetParameter () method to obtain the request parameters. If 1.jsp has <form name= " Form1 "method=" Post "action=" 2.jsp "> Please enter user name: <input type=" text "name=" username "><input type=" Submit "name = "Submit" value= "commit" ></form> the Request.getparameter ("username") method in 2.jsp to obtain the request parameters 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. There are 1.jsp and 2.jsp1.jsp want to 2.jspPass the current user name, 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"); %>

GetParameter and GetAttribute differences in JSPs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.