• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Struts2框架简介及用法介绍

java 搞代码 4年前 (2022-01-09) 21次浏览 已收录 0个评论
文章目录[隐藏]

原文地址:点击前往

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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Struts2框架简介及用法介绍

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址