Struts2 the action gets the JSP page information

Source: Internet
Author: User

Some time ago in the use of Struts2, more is considered by the JSP get action stored in the session or request key.

Such as:

Public String getinfbysal () {
Connection con = oracleconnectionmanager.getconnection ();
Userdao Userdao = new Userdao ();
Arraylist<userbean> userlist = Userdao.getuserinfbysal (Con,this.lowsal, this.hisal);
if (userlist!= null) {
Actioncontext ac =actioncontext.getcontext ();
Ac.put ("UserList", userlist);
Return "Success";
}else{
Return "Failed";
}
}

The put () method using Actioncontext, which is the action context, stores the required delivery information as a key-value pair in the Request object. This shows that Actioncontext is a request level class.


And to get the JSP stored in request from the action, the key needs to be

Gets the Request object
//HttpServletRequest request = (HttpServletRequest) Ac.get from the action context (servletactioncontext.http_requ EST);
String id = request.getparameter ("id");
Gets the Request object
//String id = servletactioncontext.getrequest () getparameter ("id") from the container action context;
Convert Actioncontext to Servletactioncontext

And the session is relatively easy to get

Actioncontext.getcontext (). GetSession (). get ();

Can.

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.