我用的是myeclipse 7.5版本。怎样在Web应用中对struts 2.1配置,它说的在web.xml文件中以代码的形式把struts 2.1表示出来啊?web.xml是在Tomcat中的那个吗???我自己弄的老出错!!谢谢各位啦!

解决方案 »

  1.   


    myeclipse7.5不是可以自动部署struts2.1
      

  2.   

    是的web.xml在WEB-INF目录下,要在其中配置struts的过滤器. <filter>
       <filter-name>struts2</filter-name>
       <filter-class>
       org.apache.struts2.dispatcher.FilterDispatcher
       </filter-class>
      </filter>
      <filter-mapping>
       <filter-name>struts2</filter-name>
       <url-pattern>*.action</url-pattern>
      </filter-mapping>
      

  3.   

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <!-- 項目名称 -->
    <display-name>struts2.1</display-name> <!-- 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> <!-- セッション失効 -->
    <session-config>
    <session-timeout>30</session-timeout>
    </session-config> <!-- ようこそ -->
    <welcome-file-list>
    <welcome-file>welcome.jsp</welcome-file>
    </welcome-file-list></web-app>
      

  4.   

    用struts2 在web.xml中配置一个过滤器filterDispatcher .. 也是struts的入口。。
    配置如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <filter>
      <filter-name>struts2</filter-name>
      <filter-class>
      org.apache.struts2.dispatcher.FilterDispatcher
      </filter-class>
      </filter>
      <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>*.action</url-pattern>
      </filter-mapping>
    </web-app>