request, session, application of struts2
5026 단어 application
This is the most common method
(1) WebParaAction.java
package com.ru.action;
import java.util.Map;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
import com.ru.domain.User;
// RequestAware,SessionAware, ApplicationAware
public class webpara extends ActionSupport implements RequestAware,
SessionAware, ApplicationAware {
// ,map
private Map<String,Object> request;
private Map<String, Object> session;
private Map<String, Object> application;
//
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
if(user.getName().equals(" ")&&user.getPassword().equals("123")){
// set request,session,application
request.put("name", user.getName());
session.put("name", user.getName());
application.put("name", user.getName());
return "para";
}else{
return "error";
}
}
//
@Override
public void setRequest(Map<String, Object> request) {
// TODO Auto-generated method stub
this.request=request;
}
@Override
public void setSession(Map<String, Object> session) {
// TODO Auto-generated method stub
this.session=session;
}
@Override
public void setApplication(Map<String, Object> application) {
// TODO Auto-generated method stub
this.application=application;
}
}
(2) webpara.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
// struts2
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'webpara.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h1> request,session,application</h1>
<h2> request </h2>
<s:property value="#request.name"/>
<%=request.getAttribute("name") %>
<h2> session </h2>
<s:property value="#session.name"/>
<%=session.getAttribute("name") %>
<h2>application </h2>
<s:property value="#application.name"/>
<%=application.getAttribute("name") %>
<s:debug />
</html>
2. The second method (using the constructor with the ActionContext function)
package com.ru.action;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.ru.domain.User;
public class WebParaAction extends ActionSupport {
// map request,session application
private Map request1;
private Map session1;
private Map application1;
// jsp
private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
//
public WebParaAction() {
request1=(Map)ActionContext.getContext().get("request");
session1=ActionContext.getContext().getSession();
application1=ActionContext.getContext().getApplication();
}
//
@Override
public String execute() throws Exception {
request1.put("name",user.getName());
session1.put("name", user.getName());
application1.put("name", user.getName());
return "ok";
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Pre-Query SamplesValidate the current query criteria or provide additional query criteria programmatically, just before sending the SELEC...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.