日期:2014-05-19  浏览次数:20659 次

struts配置
struts2.1.0和struts2.1.1的web.xml配置文件怎么写

------解决方案--------------------
XML code
<filter>  
   <filter-name>struts2 </filter-name>  
   <filter-class>  
       org.apache.struts2.dispatcher.FilterDispatcher   
   </filter-class>  
   <init-param>    
      <param-name>config </param-name>    
      <param-value>struts-default.xml,struts-plugin.xml,/WEB-INF/struts.xml </param-value>    
   </init-param>  
</filter>  
  
<filter-mapping>    
   <filter-name>struts2 </filter-name>  
   <url-pattern>/* </url-pattern>    
</filter-mapping>

------解决方案--------------------
具体看官方文档。很简单的。
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


具体看
http://struts.apache.org/2.1.8.1/docs/create-struts-2-web-application-with-artifacts-in-web-inf-lib-and-use-ant-to-build-the-application.html
------解决方案--------------------
在struts的源里面有例子,你直接从里面的例子李拷贝就OK,这些东西没必要记住,你只要知道在那里能以最快的速队弄过来,而且还在控制之中弄过来的。比如说hibernate,struts,spring都有自己的参考例子。为何不看看呢???
------解决方案--------------------
struts2和web.xml配置如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!--配置Struts2-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>