配置struts2.3版本的,和以前有所不同,struts.xml是放在src下没有变。
不同的是里面的内容:
struts.xml:
1 <?xml version="1.0" encoding="UTF-8" ?> 2 3 <!DOCTYPE struts PUBLIC 4 5 "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" 6 7 "http://struts.apache.org/dtds/struts-2.1.dtd"> 8 9 <!-- 10 11 struts配置详解: package 表示包 name="struts2" 遵循命名规范 namespace 命名空间 extends 12 13 继承 表示包继承了某些包的功能 action name表示请求的名称 class 表示处理请求url converter="" 14 15 表示在请求中需要转换的类型参数 method 一个action中处理不同的请求方法 <result 16 17 name="表示和action中要执行的方法的返回值对应" type=""></result> type表示返回的结果类型 18 19 --> 20 21 <struts> 22 23 <!-- <constant name="struts.i18n.encoding" value="UTF-8" /> --> 24 25 <package name="struts2" extends="struts-default" > 26 27 <action name="hello" class="com.action.HelloAction" > 28 29 <result name="success">/welcome.jsp</result> 30 31 </action> 32 33 </package> 34 35 </struts>
配置的时候发现出现404的问题,在web.xml,配置和以前不同了。
web.xml:
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <web-app version="2.5" 4 5 xmlns="http://java.sun.com/xml/ns/javaee" 6 7 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 8 9 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 10 11 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 12 13 14 15 <filter> 16 17 <filter-name>struts2</filter-name> 18 19 <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 20 21 </filter> 22 23 <filter-mapping> 24 25 <filter-name>struts2</filter-name> 26 27 <url-pattern>/*</url-pattern> 28 29 </filter-mapping> 30 31 <!-- ... --> 32 33 <welcome-file-list> 34 35 <welcome-file>index.jsp</welcome-file> 36 37 </welcome-file-list> 38 39 </web-app>
浙公网安备 33010602011771号