HTTP Status 404 in Struts2 web application
Solution 1
I've resolved my issue by removing the user-defined library and I added the jars directly to WEB-INF/classes folder. Please, note that the jars on the picture are different from the jars listed in my question. I am only starting to learn about Struts2 so I am not even sure whether I need all those jars in there. Either way, thanks you all for your help and feedback.
Solution 2
Try keeping the jar files inside /WEB-INF/lib
Solution 3
I tried the same code on Apache Tomcat 6.0 and It is working fine there.
On Tomcat7 you may need to use Struts2 Prepare and Execute Filter.
Try with replacing your filter code with following as Filter Dispatcher is97 deprecated now.
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
Just one more question, are you able to see your System out statement on console?
BustedSanta
Updated on June 04, 2022Comments
-
BustedSanta almost 2 years
Here is my set up:
Specs:
- Tomcat 7.0.55
- jdk1.8.0_11
- Eclipse Luna
- Win 8.1
I have a Dynamic Web Project set up in Eclipse titled "Struts2Test" with following structure. Note: I am highlighting only the folders and files relevant to this question.
Struts2Test (project name) - [Java Resources] - [src] - [com.struts2action] (package) - HelloWorldAction.java - [Libraries] - [Struts2] (user defined library) - antlr-2.7.2.jar - bsf-2.3.0.jar - commons-beanutils-1.8.0.jar - commons-chain-1.2.jar - commons-digester-1.8.jar - commons-fileupload-1.1.1.jar - commons-io-1.1.jar - commons-logging-1.0.4.jar - commons-validator-1.3.1.jar - jstl-1.0.2.jar - oro-2.0.8.jar - standard-1.0.6.jar - struts-core-1.3.10.jar - struts-el-1.3.10.jar - struts-extras-1.3.10.jar - struts-faces-1.3.10.jar - struts-mailreader-dao-1.3.10.jar - struts-scripting-1.3.10.jar - struts-taglib-1.3.10.jar - struts-tiles-1.3.10.jar - [Web Content] - [WEB-INF] - [classes] - struts.xml - web.xml - error.jsp - index.jsp - success.jsp
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>Struts2Test</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
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="helloworld" extends="struts-default"> <!-- URL: hello --> <action name="hello" class="com.struts2action.HelloWorldAction" method="execute"> <result name="success">/success.jsp</result> <result name="error">/error.jsp</result> </action> <!-- more actions can be listed here --> </package> <!-- more packages can be listed here --> </struts>
HelloWorldAction.java
package com.struts2action; public class HelloWorldAction { public String execute() { System.out.println("HelloWorldAction - called"); return "success"; } }
I run and compile the program. I call the following:
http://localhost:8085/Struts2Test/hello.action
I keep getting the following error:
HTTP Status 404 - /Struts2Test/hello.action
type Status report message /Struts2Test/hello.action description The requested resource is not available.
Apache Tomcat/7.0.55
Could anyone please advise what the issue with my configuration is?