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

nhhxz33t  于 2024-01-04  发布在  其他
关注(0)|答案(2)|浏览(304)

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

  1. The requested resource(/Struts2Starter/) is not available

字符串

路径如下:

x1c 0d1x的数据
部署的Webb文件夹元素/文件/内容和部署的资源文件夹:


代码片段:
struts.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  4. "http://struts.apache.org/dtds/struts-2.0.dtd">
  5. <struts>
  6. <package name="default" extends="default">
  7. <action name="getTutorial" class="TutorialAction">
  8. <result name="success">/success.jsp</result>
  9. <result name="failure">/error.jsp</result>
  10. </action>
  11. </package>
  12. </struts>

web.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <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">
  3. <display-name>Struts2Starter</display-name>
  4. <filter>
  5. <filter-name>struts2</filter-name>
  6. <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  7. </filter>
  8. <filter-mapping>
  9. <filter-name>struts2</filter-name>
  10. <url-pattern>/*</url-pattern>
  11. </filter-mapping>
  12. </web-app>

error.jsp

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

success.jsp

  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  7. <title>Insert title here</title>
  8. </head>
  9. <body>
  10. Success Page!
  11. </body>
  12. </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配置中执行以下操作

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  4. "http://struts.apache.org/dtds/struts-2.0.dtd">
  5. <struts>
  6. <package name="default" extends="default" namespace="/">
  7. <action name=""> <!-- or you can include index.jsp file in web.xml -->
  8. <result>/index.jsp</result>
  9. </action>
  10. <action name="getTutorial" class="TutorialAction">
  11. <result name="success">/success.jsp</result>
  12. <result name="failure">/error.jsp</result>
  13. </action>
  14. </package>
  15. </struts>

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

展开查看全部
o2g1uqev

o2g1uqev2#

你已经使用

  1. http://localhost:8083/Struts2Starter/
  2. http://localhost:8083/Struts2Starter/TutorialAction
  3. http://localhost:8083/Struts2Starter/TutorialAction.action

字符串
但是它们都没有Map到action。struts.xml应该被修改并更改为正确的DTD。

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE struts PUBLIC
  3. "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
  4. "http://struts.apache.org/dtds/struts-2.3.dtd">
  5. <struts>
  6. <package name="default" extends="struts-default">
  7. <action name="getTutorial" class="TutorialAction">
  8. <result name="success">/success.jsp</result>
  9. <result name="failure">/error.jsp</result>
  10. </action>
  11. </package>


试试这个URL

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


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

展开查看全部

相关问题