简体   繁体   中英

I created a simple struts application and deployed on the tomcat but it is throwing an 404 error & tomcat is up n running on localhost

struts.xml is in src folder, JSP are in webcontent folder. I've cleaned the cache and redeployed it but still throwing 404 error.

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 is in src folder, JSP are in webcontent folder. I've cleaned the cache and redeployed it but still throwing 404 errorstruts.xml is in src folder, JSP are in webcontent folder.

Log file

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)

It Seems like your sample project is incomplete, please follow below example and first understand the way of struts 2 working. https://struts.apache.org/docs/hello-world-using-struts-2.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM