我有一个运行在Glassfish 4容器上的Struts2应用程序。该应用程序包含一个动作类SampleAction
Struts2操作映射导致错误404
package com.mysample.action;
public class SampleAction {
public String execute() {
return "success";
}
}
的支柱XML是简单的和包括:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="sayHello" class="com.mysample.action.SampleAction">
<result name="success">/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
该项目的web.xml文件看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<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>
当我去http://localhost:8080/sample_war_exploded/sayHello.action我得到一个404错误。未找到
当我去:http://localhost:8080/sample_war_exploded/success.jsp - 我获得了成功页面
为什么我映射无法正常工作?我期望通过去*/sayHello.action,我会得到成功的页面。
我试过重新部署工件,停止+重新启动服务器等。我甚至对“success.jsp”上的内容进行了一些更改,并且在重新部署时会收到这些更改。映射不能正常工作,我想知道如何解决这个问题。
你错过了配置文件吗? – 2015-01-27 09:01:49
您是否在应用程序启动时看到任何错误? – 2015-01-27 10:00:20