取得Map類型request
前三者
前三者
後三者
後三者
一
一般在Action類的構造方法
[java]
public class LoginAction
private Map request;
private Map session;
private Map application;
public LoginAction
request = (Map)ActionContext
session = ActionContext
application = ActionContext
}
public String execute() {
request
session
application
return SUCCESS;
}
}
public class LoginAction
private Map request;
private Map session;
private Map application;
public LoginAction
request = (Map)ActionContext
session = ActionContext
application = ActionContext
}
public String execute() {
request
session
application
return SUCCESS;
}
}
然後在Jsp頁面中獲取相關web元素
[html]
<body>
User Login Success!
<br />
<s:property value=
<s:property value=
<s:property value=
<s:property value=
<s:property value=
<s:property value=
<s:debug></s:debug>
<br />
</body>
<body>
User Login Success!
<br />
<s:property value=
<s:property value=
<s:property value=
<s:property value=
<s:property value=
<s:property value=
<s:debug></s:debug>
<br />
</body>
注
因此需要使用#key來訪問對象們
後面的是java腳本代碼的訪問方式
一
讓Action類實現RequestAware
[java]
import org
import org
import org
import com
public class LoginAction
private Map<String
private Map<String
private Map<String
//DI dependency injection依賴注入
//IoC inverse of control控制反轉
public String execute() {
request
session
application
return SUCCESS;
}
@Override
public void setRequest(Map<String
this
}
@Override
public void setSession(Map<String
this
}
@Override
public void setApplication(Map<String
this
}
}
import org
import org
import org
import com
public class LoginAction
private Map<String
private Map<String
private Map<String
//DI dependency injection依賴注入
//IoC inverse of control控制反轉
public String execute() {
request
session
application
return SUCCESS;
}
@Override
public void setRequest(Map<String
this
}
@Override
public void setSession(Map<String
this
}
@Override
public void setApplication(Map<String
this
}
}
在視圖(JSP)頁面中獲取相關對象
一
獲取是的HttpServletRequest/HttpSession/ServletContext
[java]
public class LoginAction
private HttpServletRequest request;
private HttpSession session;
private ServletContext application;
public LoginAction
request = ServletActionContext
session = request
application = session
}
public String execute() {
request
session
application
return SUCCESS;
}
}
public class LoginAction
private HttpServletRequest request;
private HttpSession session;
private ServletContext application;
public LoginAction
request = ServletActionContext
session = request
application = session
}
public String execute() {
request
session
application
return SUCCESS;
}
}
一
首先需要Action實現org
[java]
import javax
import javax
import javax
import org
import com
public class LoginAction
private HttpServletRequest request;
private HttpSession session;
private ServletContext application;
public String execute() {
request
session
application
return SUCCESS;
}
@Override
public void setServletRequest(HttpServletRequest request) {
this
this
this
}
}
import javax
import javax
import javax
import org
import com
public class LoginAction
private HttpServletRequest request;
private HttpSession session;
private ServletContext application;
public String execute() {
request
session
application
return SUCCESS;
}
@Override
public void setServletRequest(HttpServletRequest request) {
this
this
this
}
}
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28170.html