2016-03-15 36 views
1

如果我不包括web.xml文件,则索引文件正常打开但结果页HelloWorld.jsp正在给出404错误,并且包括web.xml索引页在给出404错误时。为什么索引页在Struts 2中给出404错误

我有index.jsp文件。 localhost:8080工作正常,但在此之后发生错误。

在这里看到:


enter image description here

+0

的可能的复制[异常起始过滤器的struts2 - 尝试添加JAR的,但同样的结果](http://stackoverflow.com/questions/17096637/exception-开始 - 过滤器struts2 - 尝试 - 添加罐 - 但是相同的结果) –

回答

0

在第一种情况下,索引文件是默认的servlet打开,可用的服务器上。

在第二种情况下,您使用已弃用的FilterDispatcher

你应该升级的Struts到最新版本,并使用

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 

了解如何编写Web应用程序描述web.xml

简单示例

配置web.xml对于框架是增加一个过滤器 和过滤器映射的问题。

FilterDispatcher实施例(web.xml):

<web-app id="WebApp_9" 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"> 

    <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> 

    <!-- ... --> 

</web-app> 
+0

感谢您的帮助。 它为我工作。 –