我的struts.xml位于'src'下,action类位于包'login'中。
这是我的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下):
<%@ 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方法:
public String execute(){
JSONObject json = new JSONObject();
json.put("success", "true");
return Action.SUCCESS;
}
当我尝试运行appn时,我收到错误“没有映射名称空间/操作名称登录”。 some1 plz可以帮助我。我做错了什么?
这是堆栈跟踪: 这是堆栈跟踪:
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)
答案 0 :(得分:1)
好的ppl,我发现了为什么我收到这个错误。我收到了warning: Unable to find parent packages json-default
,因为我刚刚在lib中添加了json-lib-2.2.2-jdk15.jar
,我不知道还要添加jsonplugin-0.32.jar
。
我现在也将动作类中的json对象作为json.toString()
返回
感谢您的评论。