Struts2框架的见解
2016-07-05 11:50
531 查看
Struts2框架的见解
本篇文章是我在整理struts2框架的详细内容时的一些见解.适合有一定的struts2开发经验的朋友们互相交流.
一:Struts2的运行原理
在 WEB 容器启动的时候加载 web.xml 文件, 核心控制器 FilterDispatcher 会加载并解析 struts.xml.客户端会发送一个请求到action,FilterDispatcher会根据web.xml中配置的后缀名进行拦截 .
FilterDispatcher根据struts.xml的配置文件信息找到某个action对应的某个类里的指定的方法
执行相关的业务逻辑之后,返回一个String.
在struts.xml中的 action 标签中的 result 标签上的 name属性的属性值与返回的 String 字符串进行匹配, 跳转到指定的 Action 或者 jsp (看您的具体实现了) .
二:Struts2中相关的注意事项与映射关系汇总
Struts2 的 Action 继承 ActionSupport ,也可以实现 Action 接口,也可以什么都不实现.在 ActionSupport 中也有与Struts1一样的 execute()方法.但是,它的返回值为 String ,且没有 mapping, form, request, response 这四个参数.重写ActionSupport中的execute()方法,且返回值大部分 情况下为String.
在提交数据的jsp页面中,name的值必须用级联属性赋值.
级联属性赋值.如:student.studentName 其中 student 必须和 action 中 声明的用来接收前台表单参数信息的 javaBean保持一致.其中的 studentName 必须和 Model 中的属性值相同.
在 action 中声明的用来接收前台表单参数信息的 javaBean ,一定要生成对应的get, set 方法.否则接收不到值.
result 的 name 的默认值为 success, type 的默认值为 dispatcher 对应的是 forward 跳转. 还可以是 redirect 或者 redirectAction.
在”struts.xml”中通常package 继承与 struts-default, action 中 的name 可以和 method 一样的.
通过 action 中返回的字符串和 result 中 的 name 属性匹配, 来找到跳转的 jsp 页面.
在进行 Ajax请求访问的时候,回调函数中的 data 指的是请求中的访问信息.
在struts.xml中的配置
<!--struts的后缀名--> <constant name="struts.action.extension" value="do" /> <!--struts的编码方式--> <constant name="struts.i18n.encoding" value="utf-8" /> <!--进行模块划分 --> <!--可维护性,可读性 --> <!--包含另外一个配置文件 --> <include file="conf/struts/struts-login.xml" /> <include file="conf/struts/struts-book.xml" /> <include file="conf/struts/struts-resource.xml" /> <include file="conf/struts/struts-member.xml" />
大家有什么好的意见,可以分享出来,大家共同学习,进步.
相关文章推荐
- JQuery+Strusts1.x无刷新登录
- java struts常见错误以及原因分析
- Struts之logic标签库详解
- 通过实例深入学习Java的Struts框架中的OGNL表达式使用
- Java的Struts框架中append标签与generator标签的使用
- struts2的select标签用法实例分析
- SSH框架网上商城项目第20战之在线支付平台
- JavaWeb Struts文件上传功能实现详解
- 在Java的Struts框架下进行web编程的入门教程
- 详解Java的Struts框架中注释的用法
- java中struts 框架的实现
- 利用Java的Struts框架实现电子邮件发送功能
- 在Java的Struts框架中ONGL表达式的基础使用入门
- 详解Java的Struts框架中栈值和OGNL的使用
- Java的Struts框架简介与环境配置教程
- Java的Struts框架中的if/else标签使用详解
- 简单说明Java的Struts框架中merge标签的使用方法
- 详解Java的Struts框架中上传文件和客户端验证的实现
- Java的Struts框架中Action的编写与拦截器的使用方法
- sprng和struts有什么区别?