Struts2 method to get the parameters of JSP page __js

Source: Internet
Author: User

Instance: Now the JSP page passes a parameter named username to the action

Url:http://localhost:8080/studentsystem/role_list.action?username=qk12333.com

first, the Get Set method is used to obtain

Define a variable with the same name in the corresponding action class and generate a set get method, then the parameter will automatically fetch the value

String username;

Public String GetUserName ()
{
return username;
}

public void Setusername (String username)
{
This.username = Username;
}

SYSTEM.OUT.PRINTLN (username)//result is qk12333.com

second, through Servletactioncontext get/import imports Org.apache.struts2.ServletActionContext;

HttpServletRequest reqeust= servletactioncontext.getrequest ();

String Username=reqeust.getparameter ("username");//Strings

Url:http://localhost:8080/studentsystem/role_list.action?username=qk12333.com&username=qk12333.com

String[] Username=reqeust.getparametervalues ("username");//Array of strings

SYSTEM.OUT.PRINTLN (username)//result is qk12333.com System.out.println (username[0));//result is qk12333.com


third, through Actioncontext get/import imports Com.opensymphony.xwork2.ActionContext;

Actioncontext context = Actioncontext.getcontext ();
Map params = Context.getparameters ();
String[] Username= (string[]) params.get ("username");

Actioncontext gets to an object such as objects or string[] System.out.println (username[0);//The result is qk12333.com

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.