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