`

struts2前后台传值汇总-(1)ActionContext-map格式

    博客分类:
  • java
阅读更多

后台调用ActionContext中的getObject(),getSession(),getApplication() 获取request,session,application.

 

package struts.test.action;

import java.sql.SQLException;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 登录练习
 * @author zk
 *
 */
//public class LoginAction implements Action {
public class LoginAction extends ActionSupport {

	//获取request对象
	ActionContext context;
	Map request1;
	Map session1;
	Map application1;
	
	
	@Override
	public String execute() throws Exception {
					
			context = ActionContext.getContext();
			request1 = (Map)context.get("request");
			session1 = context.getSession();
			application1 = context.getApplication();
			
			request1.put("req", "request1属性");
			session1.put("ses", "session1属性");
			application1.put("app", "application1属性");
			
			
			
			
			return SUCCESS;
	}

	
}

 

 

 

前台2种方式获取(EL表达式和控制反转IOC)

<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
%>
<html>
<head></head>
<body>
	<h1>adminSuc</h1>
	管理员页面	
	<br/><br/>
	requset属性接受:<s:property value="#request.req"/> <br/>
	session属性接受:<s:property value="#session.ses"/><br/>
	application属性接受:<s:property value="#application.app"/><br/>
	<br/>
	=============================
	<br/> 
	<br/><h1> 另外一种获取方法 :</h1><br/>
	requset属性接受:${requestScope.req}<br/>
	session属性接受:${sessionScope.ses}<br/>
	application属性接受:${applicationScope.app}<br/>
	<br/>
	<br/> 
	<a href="<%=path %>/login.jsp">返回</a>
</body>
</html>

 

 

  • 大小: 278 KB
0
0
分享到:
评论

相关推荐

    struts2-junit-plugin-2.1.8.jar

    可解决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...

    ActionContext介绍(在Struts2中)

    在Web应用程序开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话 (Session)的一些信息, 甚至需要直接对JavaServlet Http的请求(HttpServletRequest),响应...

    struts2中的ActionContext与ognl

    NULL 博文链接:https://lijiejava.iteye.com/blog/628636

    基于struts2注册登录ActionContext.zip

    struts2大量使用拦截器来处理请求,从而允许与业务逻辑控制器 与 servlet-api分离,避免了侵入性(所谓侵入性就是指的这个架构设计出来的部件对系统的影响范围,标签库几乎可以完全替代JSTL的标签库,并且 struts2.x...

    Struts2整合SiteMesh技巧

    xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;decorators defaultdir="/decorators"&gt; &lt;excludes&gt; &lt;pattern&gt;/exclude.jsp&lt;/pattern&gt; &lt;pattern&gt;/exclude/*&lt;/pattern&gt; &lt;/excludes&gt; ...

    struts2OGNL表达式ActionContext及valuesStack.pdf

    struts2OGNL表达式ActionContext及valuesStack.pdf

    struts2_OGNL表达式ActionContext及valuesStack

    struts2 OGNL,struts2 表达式语言,Struts2 中OGNL表达式的用法,Struts2 #,表达式语言的好处,Struts2 $,struts2 井号,星号,百分号

    Struts2中Servlet的配置

    1、在struts2的action中可以通过实现ServletResponseAware/ServletResquestAware接口 (org.apache.struts2.inteceptor.ServletResponseAware/ServletResquestAware)直接访问 HttpServletResponse/HttpServletRequest...

    Struts2 in action中文版

    第1章 Struts 2:现代Web框架 2 1.1 Web应用程序:快速学习 2 1.1.1 构建Web应用程序 2 1.1.2 基础技术简介 3 1.1.3 深入研究 6 1.2 Web应用程序框架 7 1.2.1 什么是框架 7 1.2.2 为什么使用框架 8 1.3 Struts 2框架...

    struts2 标签库 帮助文档

    Struts 2 标签库(文档手册) Tags-API-CLSW-JSP &lt;%@ taglib prefix="s" uri="/struts-tags" %&gt; 就能使用struts2.0的标签库 下面就介绍每个标签的具体应用实例说明:按字母排列 A: 1. 2. &lt;s:a href=""&gt;&lt;/s:a&gt;-...

    struts2文件上传,与struts2-xml校验

    struts2文件上传,与xml校验 struts2文件校验可通过xml配对action的名称去校验属性的值。例如UploadAction.java中有一个book的属性。那么我可以定义一个UploadAction-validation.xml去校验这个book属性的内容。 xml的...

    Struts2 s2-061 Poc分析1

    简介分析性。2. 已实例类的法调 (OgnlContext 中的对象),不允许调静态法idea 中可以通过 ActionContext.actionContex

    struts2流程与流程图

    一个请求在Struts 2框架中的处理大概分为以下几个步骤。...Struts 2的核心控制器是FilterDispatcher,有3个重要的方法:destroy()、doFilter()和Init(),可以在Struts 2的下载文件夹中找到源代码,如代码1所示。

    Struts2通过使用ActionContext类获取request和response对象

    NULL 博文链接:https://zhouhaitao.iteye.com/blog/1126042

    struts_2.3.12GA_API文档(chm版本)

    Set the field error map of fieldname (String) to Collection of String error messages. void validate() A default implementation that validates nothing. 从类 java.lang.Object 继承的方法 equals, ...

    Struts2_TypeConvertion

    这种方式主要是利用了com.opensymphony.xwork2.ActionContext类以及org.apache.struts2.ServletActionContext类,具体的方法如下所示。 获得request对象: A . HttpServletRequest request = ServletActionContext....

    Struts2 学习笔记

    01 Struts2-Action 5 一、 Struts作用: 5 二、 搭建Struts2的运行环境: 5 三、 Namespace 6 四、 标签 6 五、 Action 6 六、 路径问题的说明 8 七、 Action的动态调用方法 8 八、 Action通配符(wildcard)的配置 9 ...

    struts2验证码完整实例

    1、页面加载后,想后台发出生产验证码图片的请求,并在前台显示验证码图片,同时将验证码上的数字 通过ActionContext.getContext().getSession().put("random", randomNum.getRandomCode())将数字存放到session当中 2...

    Struts2帮助```````

    01 Struts2-Action 5 一、 Struts作用: 5 二、 搭建Struts2的运行环境: 5 三、 Namespace 6 四、 标签 6 五、 Action 6 六、 路径问题的说明 8 七、 Action的动态调用方法 8 八、 Action通配符(wildcard)的配置 9 ...

    STRUTS2获得作用域、参数响应对象及三种符号说明

    RequestMap,SessionMap,ApplicationMap, AttributeMap. struts提供两种方式访问session,request ,response,ActionContext 使用。 获得作用域及参数响应对象及三种符号说明

Global site tag (gtag.js) - Google Analytics