package com.zchen.struts2.user.action;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction1 extends ActionSupport {
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;
}
}
<body> 取得Map类型request,session,application<li>前三者:依赖于容器</li> <br /> <form name="f" action="" method="post"> 用户名:<input type="text" name="name"/> 密码:<input type="text" name="password"/> <br /> <input type="button" value="submit1" οnclick="javascript:document.f.action='login/login1';document.f.submit();" /> <input type="button" value="submit2" οnclick="javascript:document.f.action='login/login2';document.f.submit();" /> <input type="button" value="submit3" οnclick="javascript:document.f.action='login/login3';document.f.submit();" /> <input type="button" value="submit4" οnclick="javascript:document.f.action='login/login4';document.f.submit();" /> </form> </body>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="login" extends="struts-default" namespace="/login"> <action name="login*" class="com.zchen.struts2.user.action.LoginAction{1}"> <result>/user_login_success.jsp</result> </action> </package> </struts>
<body> User Login Success! <br /> <s:property value="#request.r1"/> | <%=request.getAttribute("r1") %> <br /> <s:property value="#session.s1"/> | <%=session.getAttribute("s1") %> <br /> <s:property value="#application.a1"/> | <%=application.getAttribute("a1") %> <br /> <s:debug></s:debug> <br /> </body>