1

My struts.xml is under 'src' and action class is in a package 'login'.

Here's my 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="example"  extends="json-default">
     <action name="login" class="login.LoginAction">
        <result type="json"/>
     </action>
  </package>

</struts>

My jsp(It is under /LoginEx/WebContent/Login.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">
<%@ taglib prefix="s" uri="/struts-tags" %>
</head>
<body>
    <s:form action="login.action" method="post" validate="true">
        <s:textfield label="User Id" name="userId"></s:textfield>
        <s:password name="password" label="Password"></s:password>
        <s:submit value="Login"></s:submit>
    </s:form>
</body>
</html>

The execute method in the action class:

public String execute(){
    JSONObject json = new JSONObject();
    json.put("success", "true");
    return Action.SUCCESS;
}

When I try to run the appn, I get the error "There is no Action mapped for namespace / and action name login". Could some1 plz help me out here. What am I doing wrong?

Here's the stack trace: Here's the stack trace:

WARNING: Could not find action or result
There is no Action mapped for namespace / and action name login. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)
Roman C
  • 49,761
  • 33
  • 66
  • 176
rahul
  • 11
  • 1
  • 3
  • plz provide stack trace that can help in better way!! from the first place it seems some error with mapping – Umesh Awasthi Aug 06 '11 at 18:42
  • Is LoginAction in the login package? If so, do you have any stack traces in your server log? – Steven Benitez Aug 06 '11 at 23:04
  • yes the LoginAction is in the login package. I've added the stack trace. – rahul Aug 07 '11 at 02:43
  • Add the struts2 config browser plugin, see this page: http://struts.apache.org/2.x/docs/config-browser-plugin.html then you will be able to visit a page which will tell you all the actions struts2 is aware of (it is very easy to use, and great for sanity checking). Do you think the struts.xml file is being picked up? When the application starts up there should be logs, stating that the file is being used. – Quaternion Aug 07 '11 at 05:50
  • Could you add `namespace=""` to your `s:form` and see if that works? – doctrey Aug 07 '11 at 21:25
  • I think you do not need to include the struts extension in your `s:form`'s name attribute. `` should do. – Quincy Aug 08 '11 at 07:58

1 Answers1

1

ok ppl, I found out why I was getting this error. I was getting a warning: Unable to find parent packages json-default because I had just added the json-lib-2.2.2-jdk15.jar in lib and I didn't know that jsonplugin-0.32.jar was to be added as well. I'm also now returning the json object from the action class as json.toString() Thanks for the comments.

rahul
  • 11
  • 1