package cn.edu.hpu.getValue import java.util.Map; import com.opensymphony.xwork2.ActionContext; public class LoginAction1 { private Map request; private Map session; private Map application; public LoginAction1(){ request=(Map)ActionContext.getContext().get("request"); session=ActionContext.getContext().getSession(); application=ActionContext.getContext().getApplication(); } public String execute(){ request.put("r1", "r1"); session.put("s1","s1"); application.put("a1", "a1"); return "SUCCESS"; } }
<package name="login" namespace="/login" extends="struts-default"> <action name="login*" class="cn.edu.hpu.getValue.LoginAction{1}"> <result>/User_login_success.jsp</result> </action> </package>
<input type="button" value="submit1" onclick="javascript:document.f.action='login/login1';document.f.submit();"/>
<%@taglib uri="/struts-tags" prefix="s"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>User_login_success</title> </head> <body> User Login Success!!<br/> <s:property value="#request.r1"/> | <%=request.getAttribute("r1")%><br/> <s:property value="#application.a1"/> | <%=application.getAttribue("a1")%><br/> <s:property value="#session.s1"/> | <%=session.getAttribute("s1")%><br/> <br/> <s:debug></s:debug> </body> </html>
<s:property value="#attr.r1"/> <br/> <s:property value="#attr.a1"/> <br/> <s:property value="#attr.s1"/> <br/>
原因是attr会在request,session,application这里面去搜r1,a1,s1,然后把它取出来;这个东西很少用,因为它不是精确的访问,万一值名一样的话就会出错,所以,请忘掉此方法。
转载请注明出处:http://blog.csdn.net/acmman/article/details/44238955