getting error “There is no Action mapped for namespace / and action name LoginAction” in struts2

ⅰ亾dé卋堺 提交于 2020-01-14 03:53:06

问题


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)

回答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.



来源:https://stackoverflow.com/questions/6966890/getting-error-there-is-no-action-mapped-for-namespace-and-action-name-loginac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!