Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1603363
  • 博文数量: 695
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 4027
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-20 21:22
文章分类

全部博文(695)

文章存档

2018年(18)

2017年(74)

2016年(170)

2015年(102)

2014年(276)

2013年(55)

分类: Web开发

2016-07-11 10:57:34

一个需要两个配置文件web.xml和Struts2.xml
Struts2.xml放在src目录下,这样发布的时候就会发布到WEB-INF目录的class目录下
内容如下:

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2.     <!DOCTYPE struts PUBLIC
  3.         "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
  4.         "">
  5.      
  6.     <struts>
  7.          <constant name="struts.devMode" value="true" />
  8.         <package name="default" namespace="/" extends="struts-default">
  9.             <action name="helloworld" class="com.slg.HelloWorld">
  10.                     <result>/HelloWorld.jsp</result>
  11.             </action>
  12.         </package>
  13.      
  14.     </struts>
其中namespace是对应action的访问路径,不能省略;action name 是访问的时候url,配置完成后访问helloworld.action就会返回HelloWorld.jsp页面,正常情况下可以省略.action;class是具体的访问URL后要执行的class文件的目录,也就是要对这个action要做什么操作就可以放到相应的Java文件中,然后编译成对象的class文件

点击(此处)折叠或打开

  1. <constant name="struts.devMode" value="true" />
修改配置文件后,自动更新,不用重启服务

web.xml内容:

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="" xmlns="" xsi:schemaLocation=" /web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  3.   <display-name>TestTomcat</display-name>
  4.   <welcome-file-list>
  5.     <welcome-file>index.html</welcome-file>
  6.     <welcome-file>index.htm</welcome-file>
  7.     <welcome-file>index.jsp</welcome-file>
  8.     <welcome-file>default.html</welcome-file>
  9.     <welcome-file>default.htm</welcome-file>
  10.     <welcome-file>default.jsp</welcome-file>
  11.   </welcome-file-list>

  12.   <filter>
  13.     <filter-name>struts2</filter-name>
  14.     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  15.   </filter>
  16.   <filter-mapping>
  17.     <filter-name>struts2</filter-name>
  18.     <url-pattern>/*</url-pattern>
  19.   </filter-mapping>
  20. </web-app>



阅读(526) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~