获取JSP的内置对象

获取JSP的内置对象(在 org.apache.struts2.ServletActionContext 这个包中)

 UserAction.java:

@Override
public String execute() throws Exception {
// 获取JSP的内置对象
HttpServletRequest request = ServletActionContext.getRequest();
System.out.println("contextPath --> " + request.getContextPath());

HttpServletResponse response = ServletActionContext.getResponse();
System.out.println("Locale --> " + response.getLocale());

HttpSession session = request.getSession();
System.out.println("SESSION ID --> " + session.getId());

ServletContext application = ServletActionContext.getServletContext();
System.out.println("真实路径: " + application.getRealPath("/"));

// 根据flag结果跳转
return ActionSupport.SUCCESS;
}

执行:

contextPath --> /Struts2.1Project
Locale --> zh_CN
SESSION ID --> 9E3011B6007FFDC815A9E0BF2603030A
真实路径: D:\tomcat7\apache-tomcat-7.0.75\webapps\Struts2.1Project\

 

posted @ 2017-03-06 16:58  半生戎马,共话桑麻、  阅读(170)  评论(0)    收藏  举报
levels of contents