struts-2.5.10.1 版本的HelloWorld

来源:互联网 发布:淘宝裤子女装 编辑:程序博客网 时间:2024/06/17 12:12

                                        struts-2.5.10.1版本的HelloWorld

      大家好!由于旧版本的Struts2存在漏洞,就用新版本的Struts2创建了一个简单的HelloWorld例子,同大家共享一下。碰到问题可以跟大家一起探讨。

   

1.我的环境: JDK 1.8 ,eclipse:Luna Service Release 1 (4.4.1),apache-tomcat-8.0.8,win7 64位操作系统。


2.配置步骤。

1)创建动态web工程



2).加入lib包并且应用,可以到官网下载,也可以到我的资源下载:http://download.csdn.net/detail/suxiaoluhaha/9789584


注意:引用这12个包时,javassist-3.20.0.GA.jar这个包解析不了,我就换成老版本的javassist-3.11.0.GA.jar这版本。

原先老版本有个xwork-core jar的,新版本的xwork-core jar 包被合并到struts2-core jar包里。

 3)配置web.xml 文件。

<?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>struts-2.5.10.1</display-name>     <!-- 配置struts2 的filter -->     <filter>         <filter-name>struts2</filter-name>         <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>
注意:老版本的 filter-class 是<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

新版本的filter-class 是<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>

选哪个可以在 struts2-core jar 里找到StrutsPrepareAndExecuteFilter类,然后确定用哪个路经。

4).配置struts.xml 文件。

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"    "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>    <package name="fis"  extends="struts-default">        <action name="hello" class="com.fis.struts2.test.Hello" method="sayHello">            <result name="ok">/WEB-INF/views/result.jsp</result>        </action>    </package></struts>

5).填充Action里的配置信息。

①name="hello"





②class="com.fis.struts2.test.Hello"

③method="sayHello"  和  <result name="ok">


④结果路径:<result name="ok">/WEB-INF/views/result.jsp</result>



6). 运行测试



如果要源码可以到我github下载:  https://github.com/yxzyh/struts-2.5.10.1



0 0
原创粉丝点击