Struts2 GET request Three ways

Source: Internet
Author: User

Struts2 GET request Three ways  struts2 there are three ways to get the request, preferably using the Servletrequestaware interface to inject the request object through the IOC mechanism. Get the request method in action:  code in action: Map request = (map) actioncontext.getcontext (). Get ("request"); list<task> tasks = Taskmanager.findall (); Request.put ("Tasks", tasks);  get the values in the JSP page: <s:iterator id= " Task "Value=" #request. Tasks ">       <tr class=" Table_header ">         <td><s:property value= "#task. Tname"/></td>         <td><s:property value= "#task. Tuid"/></td>         <td><s:property value= "#task. Tstarttime"/></td>         <td><s:property value= "#task. TendTime"/></td>         <td><s:property value= "#task. Tstate"/></td>       &Nbsp; <td><input type= "Radio" id= "Choose" name= "Choose" onclick= "GetId (this.value)" Value= "<s: Property value= ' #task. Tid '/> '/></td>        </tr>< /s:iterator>-------------------------------------------------------------------------------------------- Method Two: Through the Servletactioncontext class to obtain, using the STRUTS2 experience if processing get parameter is Chinese, can only use this method to handle garbled problem  action code: HttpServletRequest Request = Servletactioncontext.getrequest (); Request.setattribute ("username", "Zhangsan");  get the values in the JSP       <s:property value= "#request. Username" > or ${requestscope.req}---------------------- ----------------------------------------------------------------------  Method Three: The code in the request object action is injected through the Servletrequestaware interface via the IOC mechanism: action implements the Servletrequestaware interface, implements the method in the interface       private httpservletrequest request;     //implementation of the interface method       public void Setservletrequest (HTTPservletrequest request) {      this.request = request;      }     //then you can use the      public String execute in the Execute () method ( {      request.setattribute ("username", "Zhangsan");       request.getsession (). Getservletcontext (). Getapplication (); Get application     }      The method must be implemented, and the method is automatically called        This method will pass the created Request object to you in the process of being called, you can assign it to the variables in this class, and then request can use the        Note: The Setservletrequest () method must be executed before the Execute () method is invoked  

Struts2 GET request three ways

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.