1. Generally, define a member variable in the action, and then provide the get/Set Method for this member variable. The value of this variable can be obtained on the JSP page.
1) define member variables in action
// Define a member variable private string message; // provides the get/Set Method Public String getmessage () {return message;} public void setmessage (string message) {This. message = message ;}
2) set the value on the JSP page.
$ {Message} or <s: property value = "message"/>
2. But the number of defined member variables is too large.CodeIt takes a long time. In this case, you can use some servlet APIs to access values: httpservletrequest, httpsession, and servletcontext. Struts2 encapsulates the three objects with map, so that we can use the map object to access data.
1) store values in actions
Actioncontext = actioncontext. getcontext (); // get httpservletrequestmap <string, Object> request = (MAP) actioncontext. get ("request"); Request. put ("A", "A is in request"); // get httpsession // Map <string, Object> session = (MAP) actioncontext. get ("session"); Map <string, Object> session = actioncontext. getsession (); Session. put ("B", "B is in session"); // get servletcontext // Map <string, Object> application = (MAP) actioncontext. get ("application"); Map <string, Object> application = actioncontext. getapplication (); application. put ("C", "C is in application ");
2) set the value on the JSP page.
$ {A }$ {B }$ {c} or $ {requestscope. A }$ {sessionscope. B }$ {applicationscope. c}