JSP 请求的资源(/ProjectName/)在Struts 2中不可用

nhhxz33t  于 5个月前  发布在  其他
关注(0)|答案(2)|浏览(73)

我已经创建了一个Web动态项目Struts2Starter,对于Target运行时,Web容器是Apache Tomcat 7。
当我运行这个项目时,它给出了一个错误:

The requested resource(/Struts2Starter/) is not available

字符串

路径如下:

x1c 0d1x的数据
部署的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>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
      <display-name>Struts2Starter</display-name>
      
     
      <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>

error.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Error Page!
</body>
</html>

success.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Success Page!
</body>
</html>


然而,当我运行其他web项目时,它们运行得很好。我在web.xml中提供了欢迎文件。后来我删除了它,因为我不需要它。
我试着跑步:http://localhost:8083/Struts2Starter/http://localhost:8083/Struts2Starter/TutorialAction http://localhost:8083/Struts2Starter/TutorialAction. action
由于编译器未找到可用的项目,因此所有错误均相同。
项目已构建。端口是8083而不是8080,因为8080已经用于某些服务。然而,正如我前面提到的,其他Web项目使用Apache 7运行良好,使用8083。在项目的部署程序集中,我已经将我的用户库“Struts2”(如上面的项目资源管理器图像所示)Map到部署路径“WEB-INF/lib”。
我不能够弄清楚为什么项目没有运行,任何建议?我已经提到了类似的问题,但他们大多数是servlet和我没有做任何servletMap,而是使用过滤器的其他线程。

错误快照:

kcrjzv8t

kcrjzv8t1#

尝试在您的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>

字符串
如果不提供命名空间默认命名空间为“”空字符串,这里是documentation

o2g1uqev

o2g1uqev2#

你已经使用

http://localhost:8083/Struts2Starter/
http://localhost:8083/Struts2Starter/TutorialAction
http://localhost:8083/Struts2Starter/TutorialAction.action

字符串
但是它们都没有Map到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>


试试这个URL

http://localhost:8083/Struts2Starter/getTutorial
http://localhost:8083/Struts2Starter/getTutorial.action


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

相关问题