简体   繁体   中英

how to pass a value from action to jsp in google app engine?

I want to pass en value from my action to the result jsp file in google app engine. google app engine 1.4.3 for java and strut2 2.1.8.1

with the instruction of http://programmingpanda.blogspot.com/2009/07/struts-2-ongl-issue-on-google-app.html I already fixed the ongl listener.

in my action:

public String execute()
{
    ActionContext.getContext().getValueStack().set("user", "LovelyCat");
    return "success";
}

and the result page is this jsp page, and i try to get "user" in it:

    <%
    String name = (String)ActionContext.getContext().getValueStack().findValue( "user" );  
    out.write(name);
    %>

but name is null and it prints nothing. guys, please help me.

Use this

public String execute() {
    ActionContext.getContext().put("user", "LovelyCat");
    return SUCCESS;
}

.jsp

<s:property value="user" />

or more optimal

${user}

Do it the struts way. Just set the value in an action class property and then access it in JSP using the struts tags like <s:property>

In Action class:

public String execute()
{
   this.setUser("LovelyCat");
   return "success";
}

In JSP:

<s:property value="user"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM