struts2的学习之旅

按照流程:

一、struts2环境的搭建

  1、下载struts2

    不知为什么在https://struts.apache.org/download.cgi#struts2522网站很难下载,最终找了其他一个博客网站网站下载了struts2.3.16.1版本,

  2、将jar包导入到WEB-INF下的lib文件目录下。

   3、配置struts核心过滤器

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
 3   <display-name>mobile_scm</display-name>
 4   <welcome-file-list>
 5     <welcome-file>index.jsp</welcome-file>
 6   </welcome-file-list>
 7   <filter>
 8     <filter-name>Struts2</filter-name>
 9     <filter-class>
10             org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
11         </filter-class>
12   </filter>
13   <filter-mapping>
14     <filter-name>Struts2</filter-name>
15     <url-pattern>/*</url-pattern>
16   </filter-mapping>
17 </web-app>

  4、配置struts.xml

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 4     "http://struts.apache.org/dtds/struts-2.3.dtd">
 5 
 6 <struts>
 7     <!-- 定义以什么扩展名的形式来执行,不配置的则以.action的形式来执行 -->
 8     <!--  <constant name="struts.action.extension" value="do" />-->
 9     <!-- 是否为开发模式 ,部署的时候设置为false-->
10     <constant name="struts.devMode" value="true" />
11     <constant name="struts.enable.DynamicMethodInvocation" value="false" />
12         <!-- package:包
13              namespace属性:为当前包下的所有action设置一个全局路径
14              package的name:就是一个名字而已,没有具体的意义
15          -->
16     <package name="default" namespace="/" extends="struts-default">
17         <!-- action标签:用来配置一个action类
18              name属性:虚拟路径
19              class:action类的具体路径,如不设置class则直接递转至结果
20              method:action类中具体的action方法
21          -->
22         <action name="start" method="{1}">
23             <result>
24             /WEB-INF/index.jsp
25             </result>
26         </action>
27     
28     </package>
29 </struts>

猜你喜欢

转载自www.cnblogs.com/yuanqisheng/p/12468134.html