Several ways to pass parameters to the action in a JSP

Source: Internet
Author: User

<form name= "thisform" method= "POST" action= "index.jsp" >

form is the form, and the double quotes are filled with the path you want to submit to this form. (another page, for example).

Method= "POST" refers to the way of submission, which means that the submission is not displayed in the Address bar when submitting information (such as account password). For the user's information security.
Name= "" Here double quotes inside refers to a name you want to give you the form.

What are the methods in the JSP page that can pass parameters? How does the page's parameters pass to the action?

Parameter passing in a JSP
1: Use the form to pass the value:
<form action= "target.jsp" > <input type=text name= "Usename" value= "Tom" ></form>
2:l using hidden fields to pass values
<form action= "target.jsp" > <input type=hidden name= "test" value= "test" ></form>
3: Use cookie object to pass
Cookie Cookie=new Cookie ("My", "Liuliu")
Cookie.setmaxage (60*60);(the maximum lifecycle in seconds)
Response.addcookie (cookie);
Cookie[] Cookies=request.getcookies ();(can access the value by traversing this array)
4:session
Java.util.map<string, object> session = Actioncontext.getcontext (). GetSession ();
Session.put ("S_username", username);
String username = (string) session.get ("S_username");
Session.setattribute ("ParamName", paramname);
String Name=session.getattribute ("ParamName")
5: Through the link to pass
String name=request.getparameter ("name");
<a href= "Welcome.jsp?name=<%=name%>" >


Related Article

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.