100分求助!Struts2 Jquery Ajax报错:No result defined for action...

jeans_zh 2010-10-09 04:51:08
jsp:
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>

<html>
<head>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jquery-1.4.2.js"></script>
<script type="text/javascript">
function checkName(){
var userName = $("#userName").val();
$.ajax({
type:"POST",
dataType:"json",
url:"checkName.check.do",
data:{
'userName' : userName
},
success: function(data) {
if (data) {
alert("data:"+data);
}
}
});
}
</script>
</head>
<body>
<s:form action="user.doInsert.do" method="post">
<s:textfield id="userName" name="userVO.userName" label="userName" onchange="checkName();"/><br>
<s:textfield name="userVO.phone" label="phone"/><br>
<s:textfield name="userVO.email" label="email"/><br>
<s:submit/>
</s:form>
</body>
</html>

struts2 action:
public String check() {
try {
logger.info("============== checkUserName begain ================");
UserVO userVO = userService.checkUserName(name);

if(userVO==null){
this.result="success";
}else{
this.result = "error";
}
} catch (Exception e) {
this.setMessage("find by userName hodo GUI error: User ");
logger.error(e);
return this.dispatcher("error");
}
return SUCCESS;
}

struts.xml:
<package name="json" extends="json-default">
<action name="checkName" method="check" class="checkNameAction">
<result type="json">
<param name="root">
result
</param>
</result>
</action>
</package>

控制台错误信息:
No result defined for action com.xpow.hodo.web.action.ajax.CheckNameAction and result success
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:364)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
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:857)
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)

页面提示信息:
Struts Problem Report

Struts has detected an unhandled exception:
# Messages: No result defined for action com.xpow.hodo.web.action.ajax.CheckNameAction and result success
Stacktraces
No result defined for action com.xpow.hodo.web.action.ajax.CheckNameAction and result success

com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:364)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)


ps:如果把action的方法名改为execute,把struts.xml配置文件里的method="check"去掉,则可以运行,不报错。
...全文
693 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
z306560366 2011-12-20
................................一样的问题
回复
newjay 2011-03-30
可能是因为你data对象中的 userName 值为null所致

data:{
'userName' : userName
},
回复
Jeanx 2010-10-20
使用struts2动态方法
<!-- 动态方法 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />

通过checkName!check.do访问。
回复
qinhualee 2010-10-09
不清楚 url:"checkName.check.do", 是什么意思
struts2默认处理的是后缀为.action 的请求,用.do要在配置文件中配置
回复
cx170817965 2010-10-09

public String jsonAction() {
PrintWriter writer = response.getWriter();
String json= 组织json字符串();
writer.write(json);
return null;
}
回复
cx170817965 2010-10-09
配置文件action里不用配置<result>
直接写<action XXX></action>
action类里把你需要的json对象用字符串拼接起来 然后write到页面
return null 就可以了
回复
shanxmxj 2010-10-09
<action name="checkName" method="check" class="checkNameAction">

No result defined for action com.xpow.hodo.web.action.ajax.CheckNameAction


回复
shanxmxj 2010-10-09
struts.xml:
<package name="json" extends="json-default">
<action name="checkName" method="check" class="checkNameAction">
<result type="json">
<param name="root">
result
</param>
</result>
</action>
</package>

控制台错误信息:
No result defined for action com.xpow.hodo.web.action.ajax.CheckNameAction and result success

回复
liubo_0329 2010-10-09
我觉得是你 传参有问题
在JavaScript里面 自己多调试下 看看吧
回复
小武茶庄 2010-10-09
应该在你的struts.xml配置出错了吧.检查一下CheckNameAction 中的result
回复
tracyXiaoAi 2010-10-09
你的这个url:"checkName.check.do",
应该把.check去掉吧
你已经配置了checkName调用的方法是check了
回复
jeans_zh 2010-10-09
[Quote=引用 1 楼 allyzhou 的回复:]

No result defined for action com.xpow.hodo.web.action.ajax.CheckNameAction and result success
没有为CheckNameAction 配置success的路径,去struts.xml中看看为CheckNameAction 配置的结果界面吧
[/Quote]

返回的是json值,不跳转、转发页面的!
回复
Allyzhou 2010-10-09
No result defined for action com.xpow.hodo.web.action.ajax.CheckNameAction and result success
没有为CheckNameAction 配置success的路径,去struts.xml中看看为CheckNameAction 配置的结果界面吧
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2010-10-09 04:51
社区公告
暂无公告