Java 为什么我的简单Struts2示例不起作用?

Java 为什么我的简单Struts2示例不起作用?,java,eclipse,jsp,struts2,glassfish,Java,Eclipse,Jsp,Struts2,Glassfish,我正在将Glassfish 4.0与Eclipse Luna 4.4.0结合使用,并下载了最新的struts2库。我已经将所有struts2罐添加到项目中,只是为了确定。我创建了一个动态Web项目。这是我的web.xml文件: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.o

我正在将Glassfish 4.0与Eclipse Luna 4.4.0结合使用,并下载了最新的struts2库。我已经将所有struts2罐添加到项目中,只是为了确定。我创建了一个动态Web项目。这是我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
    <display-name>Struts2Starter</display-name>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <init-param>
            <param-name>actionPackages</param-name>
            <param-value>org.demian.javabrains.action</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <constant name="struts.devMode" value="true" />
    <package name="basicstruts2" extends="struts-default">
        <action name="getTutorial" class="org.demian.javabrains.action.TutorialAction" method="execute">
            <result name="success">/success.jsp</result>
            <result name="error">/error.jsp</result>
        </action>
    </package>
</struts>
我创建的其他两个页面是简单的
.jsp
页面:
success.jsp
error.jsp
,都在主目录中。如果我输入此url:
http://localhost:8080/Struts2Starter/success.jsp
,我获得了成功页面,这意味着Glassfish正在工作,但如果我输入此url:
http://localhost:8080/Struts2Starter/getTutorial.action
我总是收到http错误404。我按照本页上的说明进行操作:。谁能告诉我我做错了什么

编辑 我尝试通过插入此链接,使用
struts2 config browser插件调试应用程序

<a href="<s:url action="index" namespace="config-browser" />">Launch the configuration browser</a>

进入我的
success.jsp
页面,如下所示:。当我点击链接时,它给出了另一个404错误。我不明白。好像Struts2根本不起作用。以下是启动服务器时的日志:

编辑1
我安装了Tomcat 8.0.11,下面是启动服务器时收到的错误消息:

我终于设法使它工作了!我做的第一件事是移除所有我包含的罐子,只添加我需要的罐子。以下是我包括的罐子:

在此之后,我在项目的Properties->Deployment程序集中配置了库:

我的web.xml文件是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
    <display-name>Struts2Tutorial</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <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>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <constant name="struts.devMode" value="true" />
    <package name="basicstruts2" extends="struts-default">
        <action name="getTutorial" class="org.demian.javabrains.action.TutorialAction" method="execute">
            <result name="success">/success.jsp</result>
            <result name="error">/error.jsp</result>
        </action>
    </package>
</struts>

结构2自动化
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
支柱2
org.apache.struts2.dispatcher.ng.filter.strutspreadexecutefilter
支柱2
/*
我的struts.xml文件是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
    <display-name>Struts2Tutorial</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <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>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <constant name="struts.devMode" value="true" />
    <package name="basicstruts2" extends="struts-default">
        <action name="getTutorial" class="org.demian.javabrains.action.TutorialAction" method="execute">
            <result name="success">/success.jsp</result>
            <result name="error">/error.jsp</result>
        </action>
    </package>
</struts>

/success.jsp
/error.jsp

我仍然不知道到底是什么问题,但我想这可能是因为struts2库中的依赖关系。

您有任何例外吗?尝试从web.xml文件中删除
init param
。打开devMode并将日志记录设置为debug。是否调用了
execute()
方法?您还可以尝试将
namespace=“/”
添加到包声明中。我删除了
init参数。我还认为这是一个将
struts.xml
文件放在哪里的问题,所以我将其粘贴到了所有地方,但仍然不起作用@DaveNewton我认为根本没有调用该方法。它没有找到类,只发出404消息。这是现在文件结构的屏幕截图:@Ariel您应该在问题中包括目录树作为文本格式的代码。你说的“找不到类”到底是什么意思?默认情况下,
struts.xml
文件应该位于类路径的根目录下。它位于类路径的根目录下。我把它放在src文件夹中,我真的认为下次我会使用Maven。