gpt4 book ai didi

java - 我创建了一个简单的 struts 应用程序并部署在 tomcat 上,但它抛出 404 错误并且 tomcat 已在本地主机上运行

转载 作者:行者123 更新时间:2023-11-28 23:21:27 27 4
gpt4 key购买 nike

struts.xml 在src 文件夹中,JSP 在webcontent 文件夹中。我已经清理缓存并重新部署它,但仍然抛出 404 错误。

package com.test;

public class Learn {

public String execute(){
System.out.println("Learning struts");
return "success";
}
}

struts.xml
----------
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">

<action name="product" class="com.test.Learn">
<result name="success">success.jsp</result>
<result name="failure">failure.jsp</result>
</action>

</package>
</struts>

failure.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>
Successfully tested failure.
</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>
Struts 2
</body>
</html>



package com.test;

public class Learn {

public String execute(){
System.out.println("Learning struts");
return "success";
}
}

struts.xml
----------
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" extends="struts-default">

<action name="product" class="com.test.Learn">
<result name="success">success.jsp</result>
<result name="failure">failure.jsp</result>
</action>

</package>
</struts>

failure.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>
Successfully tested failure.
</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>
Struts 2
</body>
</html>

struts.xml 在src 文件夹中,JSP 在webcontent 文件夹中。我已经清理缓存并重新部署它但仍然抛出 404 errorstruts.xml 在 src 文件夹中,JSP 在 webcontent 文件夹中。

日志文件

127.0.0.1 - - [25/Mar/2017:00:06:36 -0500] "GET / HTTP/1.1" 200 11452
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:06:37 -0500] "GET /startStrut/ HTTP/1.1" 404 1016
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:06:48 -0500] "GET /startStrut/sampath.action HTTP/1.1" 404 1044
127.0.0.1 - - [25/Mar/2017:00:10:22 -0500] "GET / HTTP/1.1" 200 11452
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:10:23 -0500] "GET /startStrut/ HTTP/1.1" 404 1016
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:15:21 -0500] "GET /startStrut/ HTTP/1.1" 404 1016
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:15:34 -0500] "GET /startStrut/sampath.action HTTP/1.1" 404 1044
127.0.0.1 - - [25/Mar/2017:00:17:16 -0500] "GET / HTTP/1.1" 200 11452
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:17:16 -0500] "GET /TestServlet/ HTTP/1.1" 404 1018
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:17:23 -0500] "GET /TestServlet/Serve HTTP/1.1" 200 23
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:31:36 -0500] "GET / HTTP/1.1" 200 11452
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:31:36 -0500] "GET /tomcat.css HTTP/1.1" 200 5931
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:31:36 -0500] "GET /tomcat.png HTTP/1.1" 200 5103
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:31:36 -0500] "GET /bg-nav.png HTTP/1.1" 200 1401
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:31:36 -0500] "GET /bg-upper.png HTTP/1.1" 200 3103
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:31:36 -0500] "GET /bg-middle.png HTTP/1.1" 200 1918
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:31:36 -0500] "GET /asf-logo-wide.svg HTTP/1.1" 200 26726
0:0:0:0:0:0:0:1 - - [25/Mar/2017:00:31:36 -0500] "GET /bg-button.png HTTP/1.1" 200 713
127.0.0.1 - - [25/Mar/2017:15:54:44 -0500] "GET / HTTP/1.1" 200 11452
0:0:0:0:0:0:0:1 - - [25/Mar/2017:15:54:47 -0500] "GET /startStrut/ HTTP/1.1" 404 1016
0:0:0:0:0:0:0:1 - - [25/Mar/2017:16:08:15 -0500] "GET /startStrut/production.action HTTP/1.1" 404 1050.




26-Mar-2017 12:28:47.810 INFO [http-nio-8080-exec-3] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
26-Mar-2017 12:28:47.812 SEVERE [http-nio-8080-exec-3] org.apache.catalina.core.StandardContext.filterStart Exception starting filter struts2
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:509)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:490)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4700)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5340)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1284)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:666)
at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:217)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

最佳答案

您的示例项目似乎不完整,请按照下面的示例首先了解 struts 2 的工作方式。 https://struts.apache.org/docs/hello-world-using-struts-2.html

关于java - 我创建了一个简单的 struts 应用程序并部署在 tomcat 上,但它抛出 404 错误并且 tomcat 已在本地主机上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43013128/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com