Write an action class:
public class Loginaction{public String execute () {return SUCCESS;} public void SetValue (Somebean value) {This.value=value;} Public Somebean GetValue () {return this.value;} private Somebean value;}
Write The Bean class again:
public class Somebean{public String GetName () {}public void SetName (string name) {}}
Method One:
Use an OGNL expression. You can use the tag that comes with struts, and they all support OGNL, such as S:property. As an example:
<!--test.jsp--><%@ page contenttype= "Text/html;charset=utf-8" pageencoding= "Utf-8"%><%@ taglib Prefix= "S" uri= "/struts-tags"%><s:property value= "Value.name"/>
When you visit loginaction, the S:property tag will show GetValue (). GetName ();
If you want to learn more about struts2 tags and ognl expressions suggest finding more detailed information.
Method Two:
Of course, using the nature of the JSP itself. Get values by request and session.
Let's change the action class:
public class Loginaction{public String execute () {Somebean value=new somebean (); Value.setname ("Sfsfjsfje"); Actioncontext Context=actioncontext.getcontext ();//Put Attributecontext.put in Request ("value", value);// Put Context.getsession () in the session. Put ("value", value); return SUCCESS;}}
Next we change the page:
<!--test.jsp--><%@ page contenttype= "Text/html;charset=utf-8" pageencoding= "Utf-8"%><%@ taglib Prefix= "S" uri= "/struts-tags"%><%= ((Somebean) Request.getattribute ("value")). GetName ()%><%= (( Somebean) Session.get ("value")). GetName ()%>
Struts2 the action to pass a value to the page