「Struts2」sessionとrequestを取得するコード
1.Actionの書き方
public class LoginActionTwo extends ActionSupport implements RequestAware,SessionAware, ApplicationAware {
private Map<String, Object> request;
private Map<String, Object> session;
private Map<String, Object> application;
//DI dependency injection
//IoC inverse of control
public String execute() {
request.put(“changfar1", “changfar1");
session.put(“changfas1", “changfas1");
application.put(“changfaa1", “changfaa1");
return SUCCESS;
}
@Override
public void setRequest(Map<String, Object> request) {
this.request = request;
}
@Override
public void setSession(Map<String, Object> session) {
this.session = session;
}
@Override
public void setApplication(Map<String, Object> application) {
this.application = application;
}
}
2.JSP画面にrequest/session/applicationを取得する
<s:property value="#request.changfar1″/> | <%=request.getAttribute(“changfar1") %> <br />
<s:property value="#session.schangfa1″/> | <%=session.getAttribute(“changfas1") %> <br />
<s:property value="#application.changfaa1″/> | <%=application.getAttribute(“changfaa1") %> <br />
<s:property value="#attr.changfaa1″/><br />
<s:property value="#attr.changfas1″/><br />
<s:property value="#attr.changfar1″/><br />