There is no Action mapped for namespace [/] and action name [] associated with context path [duplicate]
Asked Answered
A

8

9

I've looked through all similar Q's on stackoverflow but it didn't help, sorry. The main difference I have from all of them is that I got EMPTY action name in error message. Googling didn't help :( Hope someone just could give a hint where to look for the source of the problem. thx

Error:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with context path [/LoginApplication].

--------------------------------------------------------------------------------

type Status report

message There is no Action mapped for namespace [/] and action name [] associated with context path [/LoginApplication].

description The requested resource (There is no Action mapped for namespace [/] and action name [] associated with context path [/LoginApplication].) is not available.

WARNING: Could not find action or result: /LoginApplication/
There is no Action mapped for namespace [/] and action name [] associated with context path [/LoginApplication]. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

web.xml

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Struts 2 Web Application</display-name>

<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>

</web-app>

struts.xml

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

<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.devMode" value="true" />

<constant name="struts.custom.i18n.resources" value="ApplicationResources" />

<package name="user" namespace="/" extends="struts-default">
<!-- http://localhost:8080/Struts-Example/User/Login.action -->
<action name="login">
<result>/Pages/HomePage.jsp</result>
</action>

<action name="validatelogin" class="/LoginApplication/src/ValidateLogin"
method="execute">
<result name="Success">/Pages/Success.jsp</result>
<result name="Failure">/Pages/Failure.jsp</result>

</action>
</package>
</struts>

Pages: HomePage.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Validate Login</title>
</head>
<body>
<s:form action="login" method="execute">
<s:textfield name="username" key="Username" size="20" />
<s:password name="password" key="Password" size="20" />
<s:submit />
</s:form>
</body>
</html>

Success.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>

<head>
<title>Login Application - Authorized</title>
</head>

<body>
Congratulations, <s:property value="username" />!
Welcome to Struts 2 world.
</body>
</html>

Failure.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>

<head>
<title> Login Application - Unauthorized</title>
</head>

<body>
Sorry, You have entered an invalid Username / Password
</body>
</html>

ValidateLogin.java

public class ValidateLogin 
{
public String username;
public String password;

public String getUsername() 
{
    return username;
}

public void setUsername(String username) 
{
    this.username = username;
}

public String getPassword() 
{
    return password;
}

public void setPassword(String password) 
{
    this.password = password;
}

public String execute() 
{
    if (this.username.equals("pinkesh") &&    
this.password.equals("pinkesh"))//((this.username.equals("pinkesh")) &   
(this.password.equals("pinkesh")))
        return "Success";
    else
        return "Failure";
}
}

well..image is impossible so the project structure is:

src/
----ValidateLogin.Java
WenCOntent
-----+User
--------+Pages
------------+HomePage.jsp
------------+Success.jsp
------------+Failure.jsp
-----+web.xml
-----+struts.xml
Annadiane answered 8/8, 2014 at 16:16 Comment(6)
The error is exactly what the message says: you're trying to access /, apparently, e.g., no action name. There is no action configured there, all your actions have names, like /login and /validateLogin. Also, JSP pages should go under WEB-INF to avoid direct client access. And please consider better indentation hygiene.Instill
Thanks a lot Dave. Can you please suggest what changes should I make in the struts.xml to rectify this. I tried putting the JSP pages under the WEB-INF but still got the same error.Annadiane
Are you using eclipse?Napoleonnapoleonic
What url do you enter, seems http://localhost:8080/Struts-Example?Boger
Roman: I use localhost:8080/LoginApplication/login.actionAnnadiane
Parth: I use Eclipse. I corrected the class specification, but I still have the same issue.Annadiane
B
7

I was also getting similar error. The resolution was that "struts.xml" file was in "web" folder.

It MUST be in the "src" source folder.

Make the change and restart the server.

Bonnell answered 18/6, 2015 at 17:43 Comment(0)
R
2

By default, the program will find index.jsp.
If you don't have index.jsp in your [/] directory, that error will happen.
Or you have to choose another file in web.xml

Solution:
In your web.xml add this code under filter-mapping

<welcome-file-list>
        <welcome-file>/Pages/HomePage.jsp</welcome-file>
</welcome-file-list>
Reefer answered 27/1, 2016 at 16:59 Comment(0)
A
1

Thanks to all. I changed my struts.xml as below correcting the errors mentioned and the naming convention and was able to solve the issue.

<?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="user" namespace="/User" extends="struts-default">
    <action name="login">
        <result>pages/HomePage.jsp</result>
    </action>

    <action name="ValidateLogin" class="com.user.struts.ValidateLogin" method="execute">
        <result name="SUCCESS">pages/Success.jsp</result>
        <result name="FAILURE">pages/Failure.jsp</result>
    </action>

</package>  
</struts>
Annadiane answered 11/8, 2014 at 20:0 Comment(0)
O
1

I was also getting the same error. Solved the issue by relocating the struts.xml location to the root directory of src folder in eclipse project

Outlandish answered 31/1, 2016 at 10:41 Comment(1)
This one worked for me. But not sure why src folder was not marked as root folder when the project was created. Thanks!Polonaise
B
1

I don't know if anyone still has this problem but this is what i did-

change your package name in "helloaction.java" class

Most of the people, including me just write how a tutorial shows so after hours of debugging i finally got the problem.

package com.tutorialspoint.struts2;

I had written the above line in my action(.java) class. which made a package "com.tutorialspoint" in src folder. But the syntax actually means there is a package tutorialspoint inside com package. So what basically the tutorial had was

src->com->tutorialspoint->helloaction.java

So after getting no solution from all the search i changed the name of my package to "practice" in both .java class & struts.xml and it worked fine.

src->practice->helloaction.java

Hopefully if anyone was doing the same mistake like me...it helped. It may not be the solution but it worked for me when everything else didn't.

Birthday answered 17/2, 2016 at 8:26 Comment(0)
L
1

make the changes on struts.xml file, <package name="default" namespace="/" extends="struts-default"> add namespace="/" attribute in package

Laveralavergne answered 7/7, 2016 at 7:20 Comment(0)
N
0

First learn how to specify a class in struts.xml

class="/LoginApplication/src/ValidateLogin" is wrong way to specify

<action name="validatelogin" class="/LoginApplication/src/ValidateLogin" <- this is wrong 
  method="execute">
     <result name="Success">/Pages/Success.jsp</result>
     <result name="Failure">/Pages/Failure.jsp</result>
</action>

You should correct it and write class="ValidateLogin" if the file name is ValidateLogin.java

If the java class file is in some package then it should be

class="yourPackageName.ValidateLogin"
Napoleonnapoleonic answered 8/8, 2014 at 17:40 Comment(0)
K
0

struts.xml file must in : "WebContent/WEB-INF/classes/" folder.

Kinny answered 8/2, 2017 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.