struts2.5初步使用教程
来源:互联网 发布:mac book air视频剪辑 编辑:程序博客网 时间:2024/05/18 20:48
1新建一个动态web应用,默认带web.xml;
2.将struts需要的包添加到WEB-INF/lib目录下,需要的包如图所示:
3.编辑web.xml,如下(关键要注意filter-class里面的内容,和前面的版本相比,这个):
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>SSHProject</display-name> <filter> <filter-name>struts2</filter-name> <!-- 这里没有ng.filter的ng --> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>4,在src目录下创建struts.xml,内容如下
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts><!-- 指定默认编码集 --> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <!-- 制定全局国际化资源文件 --> <constant name="struts.custom.i18n.resources" value="mess"/><package name="package1" extends="struts-default"><action name="login" class="cn.nju.fxd.login.LoginAction"><result name="input">/login.jsp</result><result name="error">/error.jsp</result><result name="success">/welcome.jsp</result></action></package></struts>5.在包内创建你需要的action,在struts.xml里面配置好即可。
关键是2.5版本的 struts有一些东西和前面的不一样了,总结下就是:
1.所需要的基本包比以前多了;
2.filter-class的名称也变了;
2.17号补充:action访问Servlet API
struts2提供了一个ActionContext类,用它可以访问Servlet API,常见的方法有:
Object get(Object key):类似于调用HttpServeltRequest 的 getAttribute(String name)方法;
void put(Object name,Object value):类似于调用
Map getApplication():返回一个map对象,该对象模拟了该应用的ServletContext实例;
static ActionContext getContext():静态方法,返回一个ActionContext实例,也就是从这里开始可以调用其他方法;
Map getParameters():相当于HttpServletRequest的getParameterMap()方法;
Map getSession():返回一个map对象,该map对象模拟了HttpSession实例;
void setApplication(Map application):直接传入一个map实例,将该map实例里的key-value对直接转换成application的属性名,属性值;
void setSession(Map session):直接传入一个map实例,将该map实例里的key-value对直接转换成session的属性名,属性值;
- struts2.5初步使用教程
- struts2初步使用
- struts2的初步使用
- struts2初步使用及详解
- Struts2配置与初步使用
- Android Studio初步使用教程
- Struts2初步
- Struts2初步
- Struts2初步
- struts2初步
- Android Studio-0.2.9初步使用教程
- Unity3D EasyTouch 初步使用教程(详细)
- Unity3D EasyTouch 初步使用教程(详细)
- kindeditor富文本编辑器初步使用教程
- python安装与初步使用教程
- 【学习cmake】CMake初步使用教程
- Struts2 官方教程:使用标签
- Struts2教程之一基本使用
- SVN简介
- LintCode on Array by Odd and Even
- 前端培训班出身——吐槽下16年的艰辛
- Linux Day4
- 生成式对抗网络(Generative Adversarial Nets)
- struts2.5初步使用教程
- Android EditText获取焦点并弹出软键盘
- CentOS下使用yum安装Git具体步骤
- 文档手册
- 一点公益系统模式源码
- 【opencv】动态背景下运动目标检测 SURF配准差分
- cs231n的第一次作业Softmax
- IOC模式精简结构-demo
- 8.1 QPainter