http status 404 The requested resource (/Crime/) is not available [duplicate] - java

This question already has answers here:
HTTP Status 404 - The requested resource (/ProjectName/) is not available
(3 answers)
Closed 6 years ago.
I'm using struts framework and this problem is occurred when i deploy my project....
why this error is occurred at the deploy time???
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>userLogin.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>f1</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>f1</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
</web-app>
tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="common" template="/FirstLayout.jsp">
<put-attribute name="header" value="/header.jsp"/>
<put-attribute name="body" value="/footer.jsp"/>
</definition>
<definition name="validUser" extends="common">
<put-attribute name="title" value="Login User"/>
<put-attribute name="contents" value="/userLogin.jsp"/>
</definition>
<definition name="invalidUser" extends="common">
<put-attribute name="tilte" value="Login Error" />
<put-attribute name="contents" value="/relogin.jsp" />
</definition>
</tiles-definitions>
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="p1" extends="tiles-default">
<action name="signin" class="action.LoginAction ">
<result name="success" type="tiles">validUser</result>
<result name="failure" type="tiles">invalidUser</result>
</action>
</package>
</struts>
this error is occurring while i add struts jar file in my project... earlier it was running without any error..Is there any problem with my strut file. I am using Myeclipse 8.5 and Tomcat server 6.0.
.

The thread is old, but I will post the solution anyway, as more people are learning how to write a web application using apache struts frame work, they will undoubtedly encounter the same problem.
The problem is that Eclipse does not copy the ROOT folder from Apache Tomcat to your Eclipse work place.
Just go to your Apache-Tomcat folder, then COPY the ROOT folder in the webapps folder.
Paste it into your Eclipse:
your_workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
tmp0 is your current server.
Also, just make sure you add your struts .jar files.
That's all folks
TL

404 may occur due to either not setting welcome file(but you set it) or if the server failed to deploy your project.
The second may be the reason here.
Check the console logs did the server start at all.
Secondly as you mention about the jar it may happen that you have included two jars of struts but with different versions.
Better use a build tool like Maven or Ant.
Tell if that helps.Thanks.

Related

Struts2 isn't loading my webapp...404 error?

I am a complete newbie to Struts2 and am unable to run anything involving it on tomcat in either eclipse/browser. Tomcat is working fine when I am just mapping servlets/jsp in a web.xml file, but when trying to switch to struts2 I can't get it to work. When I try to run on the server it isn't even going to my index jsp...just loading a 404 error. I followed an online tutorial when I couldn't get my app for my class running and the tutorial I can't get to run either. Here are the jar files I have added to tomcat lib/build path jars -
asm-5.0.2.jar
asm-commons-5.0.2.jar
asm-tree-5.0.2.jar
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-lang3-3.2.jar
commons-logging-1.1.3.jar
commons-logging-api-1.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.6.jar
struts-core-1.3.10.jar
struts2-dojo-plugin-2.3.20.jar
xwork-core-2.3.20.jar
filter added to web.xml -
<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>
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>
<constant name="struts.devMode" value="true" />
<package name="helloworld" extends="struts-default">
<action name="hello"
class="com.struts2.files.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
Any ideas as to why I am getting a 404 when trying to run the app?
I guess, you've added the wrong struts-core-1.3.10.jar to your classpath. That probably belongs to Struts 1.x. You need to include the latest struts2-core-2.x.x.jar from the Struts 2 framework.
A typical Struts 2 application has the following jars under WEB-INF/lib directory.
commons-fileupload-1.2.1
commons-io-1.3.2
commons-logging-1.1
freemarker-2.3.13
junit-3.8.1
ognl-2.6.11
xwork-2.1.2
struts2-core-2.1.6
struts2-convention-plugin-2.1.6 (if using annotations)
Try downloading the latests jars from struts.apache.org.
The filter class org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter belongs to Struts2 but you are using struts1 jar file struts-core-1.3.10.jar
As Ravi suggested, download the Jar file from Struts-2.3.20

Apache Velocity error in Eclipse [Java, Eclipse Luna, Velocity 2.0, VelocityView, Tomcat 7]

I want to start by specifiyng that I'm 90% new to all that means Java, Eclipse, templating engines.
In my attempt to create a velocity template that will run as intended I used Eclipse Luna(EE), Tomcat 7, Apache Velocity1.7, Velocity Tools 2.0, VelocityToolsView 2.0
PROBLEM is that when I start Tomcat from Eclipse (basicaly runing the project if you may), and go to "localhost:8080/VelocityTemplateHomework4/index.vm" it just throws me an entire page with the error "HTTP Status 500 - Error instantiating servlet class org.apache.velocity.tools.view.servlet.VelocityViewServlet"
In eclipse (EE) I have basicaly followed this tutorial:
http://thegeekhead.blogspot.ro/2009/06/how-to-configure-eclipse-tomact-55.html
I'll post my code anyway but please check the link too (maybe there is an issue there since it's kinda outdated)
SimpleServlet.java
package myPackage;
public class SimpleServlet {
private String message = "Hello Damn World!!!";
public String getMessage() {
return message;
}
public void setMessage(String m) {
message = m;
}
/** To test exception handling in templates. */
public boolean whine() {
throw new IllegalArgumentException();
}
}
web.xml
<?xml version='1.0' encoding='utf-8'?>
<web-app>
<!-- Define Velocity template compiler -->
<servlet>
<servlet-name>velocity</servlet-name>
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/toolbox.xml</param-value>
</init-param>
<init-param>
<param-name>org.apache.velocity.properties</param-name>
<param-value>/WEB-INF/velocity.properties</param-value>
</init-param>
</servlet>
<!-- Map *.vm files to Velocity -->
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
</web-app>
toolbox.xml
<?xml version="1.0"?>
<toolbox>
<xhtml>true</xhtml>
<tool>
<key>serv</key>
<scope>request</scope>
<request-path>index.vm</request-path>
<class>SimpleServlet</class>
</tool>
<data type="number">
<key>version</key>
<value>1.1</value>
</data>
<data type="boolean">
<key>isSimple</key>
<value>true</value>
</data>
<data type="string">
<key>foo</key>
<value>this is foo.</value>
</data>
<data type="string">
<key>bar</key>
<value>this is bar from velocity.</value>
</data>
<tool>
<key>map</key>
<scope>session</scope>
<class>java.util.HashMap</class>
</tool>
<tool>
<key>date</key>
<scope>application</scope>
<class>org.apache.velocity.tools.generic.DateTool</class>
</tool>
</toolbox>
velocity.properties
webapp.resource.loader.path=/WEB-INF/templates/
...and a simple index.vm (which for example if you notice on the tutorial website has an incorect closing html tag)
<html>
<body>
<h2>My text is : $serv.getMessage() </h2>
</body>
</html>
Files structure on the left:
Sorry for the long post, any help would be apreciated!
It doesn't seems to find your libraries.
I would try moving the velocity libraries into your WEB-INF/lib folder, so that they are deployed on the server with your application, or try to add the velocity libraries in the lib folder of your tomcat server.

The Struts dispatcher cannot be found while deploy

When I try to run my Spring + Struts 2 project on WL Server 9.2 (I have to user this version, so please don't ask me to user the newer version of WL Server), I had this error.
The URL address in the browser is :
http://localhost:7003/SpringStrust2/
Full stacktrace:
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
at jsp_servlet.__user._jsp__tag0(__user.java:115)
at jsp_servlet.__user._jspService(User.jsp:12)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3269)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2019)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1925)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1394)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
Here is my web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
<welcome-file-list>
<welcome-file>User.jsp</welcome-file>
</welcome-file-list>
struts.xml:
<struts>
<constant name="struts.enble.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="myapp" />
<package name="default" extends="struts-default">
<action name="user" class="user">
<result name="success">/success.jsp</result>
<result name="input">/User.jsp</result>
</action>
</package>
</struts>
user.jsp:
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Spring + Struts2</title>
</head>
<body>
<s:form action="user" method="addUser">
<s:textfield name="username" key="user.name" />
<s:submit key="submit" />
</s:form>
</body>
</html>
I'm very sure about putting files in correct folders, including jar libraries in lib folder...
Here is the list of jars I'm using:
antlr-runtime-3.0.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-lang3-3.1.jar
commons-logging-1.1.jar
freemarker-2.3.13.jar
junit-3.8.1.jar
ornl-2.6.11.jar
org.springframework.asm-3.9.9.M3.jar
org.springframework.beans-3.0.0.M3.jar
org.springframework.context-3.0.0.M3.jar
org.springframework.core-3.0.0.M3.jar
org.springframework.web-3.0.0.M3.jar
org.springframework.web.servlet-3.0.0.M3.jar
struts2-convention-plugin-2.1.6.jar
struts2-core-2.1.6.jar
struts2-spring-plugin-2.1.6.jar
xwork-2.1.2.jar
You're hitting the User.jsp file (with its S2 tags) without running through an action like the error says.
You can either:
Redirect to a Struts action from the welcome file (a common technique, and trivial)
configure the container to allow actions as welcome files
Remove the S2 tags from the welcome file
I had the same problem. My Struts 2 application was running on localhost like knife on butter but on VPS it failed. Finally the solution is that Web-Inf folder in project conflicts with web-inf folder of Tomcat.
So move your project/web-inf/web.xml contents to
usr/local/easy/share/easy-tomcat7/conf (for Cent OS)
and move your jars from youtproject/web-inf/lib to
usr/local/easy/share/easy-tomcat7/lib (for Cent OS)
For other OS do the same at respective path..
Hope this will be helpful..

There is no Action mapped for namespace / and action name tutorial

I am unable to execute my struts2 application. I am using eclipse indigo IDE, tomcat 7 and jdk 1.7.
The jar files I included are:
commons-logging-1.0.4.jar,
freemarker-2.3.8.jar,
ognl- 2.6.11.jar,
struts2-core-2.0.11.jar,
xwork-2.0.4.jar
I placed the struts.xml in classes folder in WEB-INF and I also tried it placing in
src folder but I could not able to make it. I am getting the below error on console
There is no Action mapped for namespace / and action name tutorial. - [unknown location]
index.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>
<form action="./tutorial.action">
Username: <input type="text" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
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="struts-default">
<action name="tutorial" class="com.test.TutorialAction">
<result name="success">/success.jsp</result>
<result name="failure">/failure.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.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
TutorialAction.java
package com.test;
public class TutorialAction {
public String execute() {
System.out.println("Hello from execute");
return "success";
}
}
As others have pointed out, you do not have a getTutorial action in your mapping, only a "tutorial". However, I'm going to skip over that and suggest that you learn how to sanity check a Struts2 app. Anytime you are setting up a new technology, and even when you are working with a familiar technology, it is very useful to understand how to do a basic sanity check -- in this case, you need to verify that your struts xml has been successfully parsed and the framework knows about your actions.
I HIGHLY RECOMMEND you add the Struts 2 Config Browser plugin to your struts 2 apps. To add the plugin, you just get the jar ( all struts 2 plugins are jars ) and put in your webapp's lib directory. That's it. When you start your applicaiton, hit this URL:
http://localhost:8080/starter/config-browser/index.action
And it shows you all of the actions, as well as other configurations, that the framework knows about. Essentialy struts 2 diagnostic tool, and too easy to use to not use it.
Try to add namespace attribute into you package element of struts.xml file.
Like this:
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="tutorial" class="com.test.TutorialAction">
<result name="success">/success.jsp</result>
<result name="failure">/failure.jsp</result>
</action>
</package>
</struts>
I had the same problem and I saw multiple posts on this one....here is the possible solution
I was pretty sure that I had mapped all my actions accurately, but it was showing the same error above....so I just cleaned the project and then ran it again..it worked perfectly fine...give it a try !
I encountered this so many times...so to avoid such kind of things, I just added "../eclipse.exe -clean" to the shortcut icon property....this works and u can forget about getting such kind of errors which is actually not an error....!
The error comes because the server is not able to find correct path for struts.xml .
Its better to put the struts.xml in parallel to src folder or in WEB-INF/classes.
Try this once don't append .action
<form action="tutorial">
place your struts.xml file in src outside the package or in WEB-INF classes folder.

How do I figure out why my Struts 2 action hasn't been mapped? [duplicate]

I am unable to execute my struts2 application. I am using eclipse indigo IDE, tomcat 7 and jdk 1.7.
The jar files I included are:
commons-logging-1.0.4.jar,
freemarker-2.3.8.jar,
ognl- 2.6.11.jar,
struts2-core-2.0.11.jar,
xwork-2.0.4.jar
I placed the struts.xml in classes folder in WEB-INF and I also tried it placing in
src folder but I could not able to make it. I am getting the below error on console
There is no Action mapped for namespace / and action name tutorial. - [unknown location]
index.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>
<form action="./tutorial.action">
Username: <input type="text" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
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="struts-default">
<action name="tutorial" class="com.test.TutorialAction">
<result name="success">/success.jsp</result>
<result name="failure">/failure.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.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
TutorialAction.java
package com.test;
public class TutorialAction {
public String execute() {
System.out.println("Hello from execute");
return "success";
}
}
As others have pointed out, you do not have a getTutorial action in your mapping, only a "tutorial". However, I'm going to skip over that and suggest that you learn how to sanity check a Struts2 app. Anytime you are setting up a new technology, and even when you are working with a familiar technology, it is very useful to understand how to do a basic sanity check -- in this case, you need to verify that your struts xml has been successfully parsed and the framework knows about your actions.
I HIGHLY RECOMMEND you add the Struts 2 Config Browser plugin to your struts 2 apps. To add the plugin, you just get the jar ( all struts 2 plugins are jars ) and put in your webapp's lib directory. That's it. When you start your applicaiton, hit this URL:
http://localhost:8080/starter/config-browser/index.action
And it shows you all of the actions, as well as other configurations, that the framework knows about. Essentialy struts 2 diagnostic tool, and too easy to use to not use it.
Try to add namespace attribute into you package element of struts.xml file.
Like this:
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="tutorial" class="com.test.TutorialAction">
<result name="success">/success.jsp</result>
<result name="failure">/failure.jsp</result>
</action>
</package>
</struts>
I had the same problem and I saw multiple posts on this one....here is the possible solution
I was pretty sure that I had mapped all my actions accurately, but it was showing the same error above....so I just cleaned the project and then ran it again..it worked perfectly fine...give it a try !
I encountered this so many times...so to avoid such kind of things, I just added "../eclipse.exe -clean" to the shortcut icon property....this works and u can forget about getting such kind of errors which is actually not an error....!
The error comes because the server is not able to find correct path for struts.xml .
Its better to put the struts.xml in parallel to src folder or in WEB-INF/classes.
Try this once don't append .action
<form action="tutorial">
place your struts.xml file in src outside the package or in WEB-INF classes folder.

Categories