struts2 session 1(通过ActionContext class中的方法getSession得到)
2012-09-19 17:23
417 查看
web.xml
struts.xml
java
jsp
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>StrutsTutorial</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
struts.xml
<?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> <package name="login" extends="struts-default"> <action name="test" class="action.TestAction"> <result name="success">/show.jsp</result> </action> </package> </struts>
java
package action; import java.util.Map; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class TestAction extends ActionSupport{ @Override public String execute() { ActionContext actionContext = ActionContext.getContext(); Map session = actionContext.getSession(); session.put("USER_NAME", "Test User"); return SUCCESS; } }
jsp
<%@ page contentType="text/html; charset=utf-8" language="java"%> <%@taglib prefix="s" uri="/struts-tags"%> <html> <head> </head> <body> <s:property value="#session.USER_NAME"/> </body> </html>
相关文章推荐
- struts2生成session的方法:ActionContext.getContext().getSession()
- Struts2中解耦合通过actionContext对象获取到aplication,session,request,paramter等对象
- struts2得到request,session 及action总结
- 基于struts2 通过注解跳转到后台action的方法
- Struts2 action中获取session,request对象的方法
- ssh2 action中通过ActionContext取得HttpServletRequest对象 然后使request.getParameter("参数名")得到参数值
- 关于ActionContext.getContext()取得的值是什么,和struts2如何获取request,session,appliaction作用域
- SpringMVC拦截器中通过反射得到Controller方法注解时ClassCastException解决方案
- 【JAVA学习】struts2的action中使用session的方法
- struts2-通过action从后台将json数据传到前台的方法(一)
- struts2 action中获取request session application的方法
- Struts2 中action中获取session的两种方法
- struts2-通过action从后台将json数据传到前台的方法(二)
- struts2:数据校验,通过Action中的validate()方法实现校验,图解
- struts2 action中获取request session application的方法
- struts2中Action获得request、session、application进行设值和取值的方法
- struts2的action中获取request、response、session的方法
- Struts2的Action中获得request、session和application的几种方法
- struts2:数据校验,通过Action中的validate()方法实现校验,图解
- struts2 ActionContext获取session对象有时为null