文章目录[隐藏]
原文地址:点击前往
1 什么是ValueStack
称为值栈,Struts提供的共享数据的数据结构
2 为什么要使用ValueStack
从控制器向浏览器传递数据
存储与请求相关的对象信息(session/application)
3 ValueStack对象的生命周期
请求进入到服务器端后,在内存中就会传创建一个ValueStack对象;当请求处理结束以后,ValueStack对象就会被清除
4 如何访问ValueStack中的数据
利用OGNL表达式获取
利用EL表达式获取
5 在ValueStack中存储数据的区域划分
Contents (栈结构) 利用OGNL或者EL来获取数据
Context (Map结构) 利用 #key 来获取数据
7 案例:从控制器向浏览器传值,展示valueStack区域
7.1 导包
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 "> 2 <modelVersion>4.0.0</modelVersion> 3 <groupId>cn.xiangxu</groupId> 4 <artifactId>ssh03</artifactId> 5 <version>0.0.1-SNAPSHOT</version> 6 <packaging>war</packaging> 7 <dependencies> 8 <dependency> 9 <groupId>org.apache.struts</groupId>10 <artifactId>struts2-core</artifactId>11 <version>2.3.8</version>12 </dependency>13 <dependency>14 <groupId>org.apache.struts</groupId>15 <artifactId>struts2-spring-plugin</artifactId>16 <version>2.3.8</version>17 </dependency>18 <dependency>19 <groupId>org.apache.struts</groupId>20 <artifactId>struts2-json-plugin</artifactId>21 <version>2.3.8</version>22 </dependency>23 </dependencies>24 </project>
pom.xml
7.2 配置文件
7.2.1 spring_context.xml
配置注解扫描
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 4 xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee&q<i>本文来源gaodai$ma#com搞$$代**码)网@</i>uot; 5 xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" 6 xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" 7 xmlns:jpa="http://www.springframework.org/schema/data/jpa" 8 xsi:schemaLocation=" 9 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd10 http://www.springframework.org/schema/context/spring-context-3.0.xsd11 http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd12 http://www.springframework.org/schema/jee/spring-jee-3.0.xsd13 http://www.springframework.org/schema/tx/spring-tx-3.0.xsd14 http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd15 http://www.springframework.org/schema/aop/spring-aop-3.0.xsd16 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd17 http://www.springframework.org/schema/util/spring-util-3.0.xsd">18 19 <!-- 配置组件扫描 -->20 <context:component-scan base-package="cn.xiangxu" />21 22 </beans>
spring_context.xml