Struts2 错误:请求的资源(/ProjectName/)不可用

Struts2 错误:请求的资源(/ProjectName/)不可用,struts2,struts2-namespace,Struts2,Struts2 Namespace,我已经创建了一个web动态项目Struts2Starter,对于目标运行时,web容器是ApacheTomcat7。 当我运行这个项目时,它给出了一个错误,请求的资源/Struts2Starter/不可用 以下是路径: 部署的Webb文件夹元素/文件/内容以及部署的资源文件夹中的内容: 代码片段: struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Softwa

我已经创建了一个web动态项目Struts2Starter,对于目标运行时,web容器是ApacheTomcat7。 当我运行这个项目时,它给出了一个错误,请求的资源/Struts2Starter/不可用

以下是路径:

部署的Webb文件夹元素/文件/内容以及部署的资源文件夹中的内容:

代码片段:

struts.xml

<?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>
<package name="default" extends="default">
<action name="getTutorial" class="TutorialAction">
<result name="success">/success.jsp</result>
<result name="failure">/error.jsp</result>

</action>
</package>


</struts>
由于编译器找不到可用的项目,所有项目都出现相同的错误

项目建成。端口是8083,而不是8080,因为8080已经用于某些服务。然而,正如我前面提到的,其他web项目在Apache7上运行良好,使用8083。在project的部署程序集中,我已将上面的project explorer图像中显示的用户库Struts2映射到部署路径WEB-INF/lib

我不知道为什么项目没有运行,有什么建议吗? 我已经提到了其他有类似问题的线程,但大多数都是针对servlet的,我没有做任何servlet映射,而是使用过滤器

错误快照:


谢谢。

在struts配置中尝试以下内容

<?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>
    <package name="default" extends="default" namespace="/">

        <action name=""> <!-- or you can include index.jsp file in web.xml -->
            <result>/index.jsp</result>
        </action>

        <action name="getTutorial" class="TutorialAction">
            <result name="success">/success.jsp</result>
            <result name="failure">/error.jsp</result>
        </action>

    </package>
</struts>
如果不提供名称空间,则默认名称空间为空字符串。这是你用过的

http://localhost:8083/Struts2Starter/
http://localhost:8083/Struts2Starter/TutorialAction
http://localhost:8083/Struts2Starter/TutorialAction.action
但他们两人都没有行动。应修改和更改struts.xml以获得正确的DTD

<?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="getTutorial" class="TutorialAction">
    <result name="success">/success.jsp</result>
    <result name="failure">/error.jsp</result>
  </action>
</package>

还要将所有必要的jar下载到应用程序的lib文件夹中。例如commons-lang3-3.3.2.jar

嗨,瑜伽士,我试了你的建议。还创建了index.jsp并如上所示使用。给出了名称空间。但它不起作用……还有什么建议吗?谢谢你的时间。嗨@Roman C是的,你是对的,我的URL本身是错误的。我将所有必需的jar添加到lib文件夹中。然后给出正确的URL。但它并没有起作用。有没有关于我在哪里会错过关键点的建议。?谢谢。你能执行这个动作吗?还有,为什么不配置项目的web根文件夹?您上次编辑的webb.xml是什么?Hi@Roman C webb是content directory文件夹,我将所有web文件存储在这里,核心java中的核心业务逻辑不在这里。另一方面,web.xml用于配置。在一个普通的web动态项目中,人们期望将servlet映射到JSP或URL,但由于这是struts项目,所以我不需要servlet,并且这个文件被安装用于过滤器。我在主线程中添加了一个快照,显示webb文件夹文件位于已部署的资源中。主线程中的第二个project explorer映像。谢谢。在文件部署到服务器上之前,这个文件夹是无用的,如果你把java文件放在web if下,请确保它们在web if下。在eclipse中如何配置项目对于在定义了名称的web部署描述符上运行的服务器来说毫无意义。如果没有它,您也无法运行项目,除非您使用的是resent-servlets技术。部署项目时,可以通过使用struts配置指定映射到操作的url来访问操作。不正确的映射会导致404状态代码,这是tomcat用来处理的默认servlet生成的。您好@Roman C,谢谢您花时间。我不知道如何在服务器上显式部署我的文件。我创建项目及其文件的方式与创建任何其他正在运行的web应用程序的方式完全相同。如何明确这一点?为什么要将核心java文件放在WEB/INF文件夹中。打电话的时候,我希望我是准确的。非常感谢您的时间和耐心。文件夹webb在您的部署程序集中吗?@Yogi是的,我的webb文件夹中的所有内容都在部署资源文件夹中。我将在主线程中添加其项目结构的快照。
http://localhost:8083/Struts2Starter/
http://localhost:8083/Struts2Starter/TutorialAction
http://localhost:8083/Struts2Starter/TutorialAction.action
<?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>
    <package name="default" extends="default" namespace="/">

        <action name=""> <!-- or you can include index.jsp file in web.xml -->
            <result>/index.jsp</result>
        </action>

        <action name="getTutorial" class="TutorialAction">
            <result name="success">/success.jsp</result>
            <result name="failure">/error.jsp</result>
        </action>

    </package>
</struts>
http://localhost:8083/Struts2Starter/
http://localhost:8083/Struts2Starter/TutorialAction
http://localhost:8083/Struts2Starter/TutorialAction.action
<?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="getTutorial" class="TutorialAction">
    <result name="success">/success.jsp</result>
    <result name="failure">/error.jsp</result>
  </action>
</package>
http://localhost:8083/Struts2Starter/getTutorial
http://localhost:8083/Struts2Starter/getTutorial.action