[转]http://blog.csdn.net/smcfy/article/details/5693481
为了避免与Servlet API耦合在一起,方便Action类做单元测试,Struts 2对HttpServletRequest、HttpSession和ServletContext进行了封装,构造了三个Map对象来替代这三种对象,在Action中,直接使用HttpServletRequest、HttpSession和ServletContext对应的Map对象来保存和读取数据。
(一)通过ActionContext来获取request、session和application对象的LoginAction1
ActionContext context = ActionContext.getContext();
Map request = (Map)context.get("request");
Map session = context.getSession();
Map application = context.getApplication();
request.put("greeting", "欢迎您来到程序员之家");//在请求中放置欢迎信息。
session.put("user", user);//在session中保存user对象
application.put("counter", count);
ActionContext context = ActionContext.getContext();
Map request = (Map)context.get("request");
Map session = context.getSession();
Map application = context.getApplication();
request.put("greeting", "欢迎您来到程序员之家");//在请求中放置欢迎信息。
session.put("user", user);//在session中保存user对象
application.put("counter", count);
在JSP中读取
<body><h3>${sessionScope.user.username},${requestScope.greeting}。<br>本站的访问量是:${applicationScope.counter}</h3>
</body>
<body><h3>${sessionScope.user.username},${requestScope.greeting}。<br>本站的访问量是:${applicationScope.counter}</h3>
</body>
(二)直接使用ActionContex类的put()方法
ActionContext.getContext().put("greeting", "欢迎您来到http://www. sunxin.org");
然后在结果页面中,从请求对象中取出greeting属性,如下:
${requestScope.greeting} 或者 <%=request.getAttribute("greeting")%>
分享到:
相关推荐
B.ActionContext ct= ActionContext.getContext() HttpServletRequest request= (HttpServletRequest)ct.get(ServletActionContext. HTTP_REQUEST ); 获得session对象: 在Struts2中底层的session都被封装成了...
ActionContext.getContext().put("exponent", new String(Hex.encodeHex(publicKey.getPublicExponent().toByteArray()))); // 页面里,Javascript对明文进行加密: 09 var modulus = $('#hid_modulus').val(); var...
struts2大量使用拦截器来处理请求,从而允许与业务逻辑控制器 与 servlet-api分离,避免了侵入性(所谓侵入性就是指的这个架构设计出来的部件对系统的影响范围,标签库几乎可以完全替代JSTL的标签库,并且 struts2.x...
ActionContext actionContext=ActionContext.getContext(); Object obj=actionContext.get("objName");----Object obj=request.getAttribute("objName"); actionContext.put("objName",objName);---request....
1:在action中定义的变量,在jsp页面中显示用:变量名" /> ...Map session = ActionContext.getContext().getSession(); HttpServletRequest request = ServletActionContext.getRequest (); 设置它们的值的方法
通过ActionContext.getContext().getSession().put("random", randomNum.getRandomCode())将数字存放到session当中 2、当你登录时候,提交的输入框中的验证码和session中存放的验证码比较,如果一样,则通过,不一样,则...
ActionContext ctx = ActionContext.getContext(); ctx.getApplication().put(“app”, “应用范围”);//往ServletContext里放入app ctx.getSession().put(“ses”, “session范围”);//往session里放入ses ...
System.out.println("上下文路径="+ ActionContext.getContext()); System.out.println("aaa="+ServletActionContext.getActionContext(ServletActionContext.getRequest())); filename=new String[myFile....
struts2OGNL表达式ActionContext及valuesStack.pdf
ActionContext.getContext().put("zhongZhuanInfoList", zhongZhuanInfoList); return "findInStoreTaskSUCCESS"; } // 业务方法 ----- 查询出库环节 的个人任务 public String findOutStoreTask...
Map, Object> session = ActionContext.getContext().getSession(); session.put("userName", userName); session.put("passWord", passWord); // 2. taglib标识传递 resultMsg = "注册成功"; return ...
可解决java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.get(Ljava/lang/Object;)Ljava/lang/Object; java.lang.ClassNotFoundException: com.opensymphony.xwork2.util.TextUtils struts2.1.8...
用于解决struts2升级至2.3.37时 出现java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.put(Ljava/lang/异常时,更换的xwork-core-2.3.37.jar
简介分析性。2. 已实例类的法调 (OgnlContext 中的对象),不允许调静态法idea 中可以通过 ActionContext.actionContex
ActionContext(com.opensymphony.xwork.ActionContext)是Action执行时的上下文,上下文可以看作是一个容器(其实我们这里的容器就是一个Map而已),它存放放的是Action在执行时需要用到的对象
使用Action访问ActionContext方式的网站计数器,可直接运行
string ip = IpHelper.GetRealIP(); if (ip == ConfigurationManager.AppSettings["ApiUrl"]) { //HttpContext.Current.... actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.OK); }
在Web应用程序开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话 (Session)的一些信息, 甚至需要直接对JavaServlet Http的请求(HttpServletRequest),响应...
NULL 博文链接:https://lijiejava.iteye.com/blog/628636
特征:服务器可免费使用单体模式进行渲染无状态异步操作便于集成的高阶组件增强磁通流动 可在 Flux 内容上增加你的接口更新至 React 0.13示例代码:import Fluxible from 'fluxible'; import React from '...