收到错误消息“没有为名称空间/和操作名称LoginAction映射任何操作".在struts2 [英] getting error "There is no Action mapped for namespace / and action name LoginAction" in struts2

查看:372
本文介绍了收到错误消息“没有为名称空间/和操作名称LoginAction映射任何操作".在struts2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的struts.xml在'src'下,而动作类在程序包'login'中.

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

这是我的struts.xml:

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>

我的jsp(位于/LoginEx/WebContent/Login.jsp下):

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>

动作类中的execute方法:

The execute method in the action class:

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

当我尝试运行appn时,出现错误没有为名称空间/和操作名登录映射的操作". 有人可以帮我在这里吗.我在做什么错了?

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)

推荐答案

好,请找出原因.我得到一个warning: Unable to find parent packages json-default是因为我刚刚在lib中添加了json-lib-2.2.2-jdk15.jar,但我不知道还要添加jsonplugin-0.32.jar. 我现在也将动作类的json对象返回为json.toString() 感谢您的评论.

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.

这篇关于收到错误消息“没有为名称空间/和操作名称LoginAction映射任何操作".在struts2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆