之前写的几个action都可以正常运行,validateLastName和delete都是返回ajax-success,但是delete方法可以正常运行,validateLastName就提示找不到action。
错误显示:
ERROR Dispatcher Could not find action or result: /Ssh-1/emp-validateLastName
There is no Action mapped for namespace [/] and action name [emp-validateLastName] associated with context path [/Ssh-1]. - [unknown location]
struts.xml:
<action name="emp-*" class="employeeAction" method="{1}">
<result name="list">/WEB-INF/views/emp-list.jsp</result>
<result type="stream" name="ajax-success">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
<result name="input">/WEB-INF/views/emp-input.jsp</result>
<result name="success" type="redirect">/emp-list</result>
</action>
action:
public String validateLastName() {
if (employeeService.validateLastName(lastName)) {
try {
inputStream = new ByteArrayInputStream("1".getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else {
try {
inputStream = new ByteArrayInputStream("0".getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return "ajax-success";
}
调用:var url = "emp-validateLastName";
var args = {
"lastName" : val,
"time" : new Date()
};
$.post(url, args, function(data)
名称不对吧
名称没问题吧 你看我代码就知道
@脑热: url不对
@ZXJ~佳: 那要改成啥
@ZXJ~佳: url=validateLastName 肯定是行不通的
@脑热:action 加个/符号
@脑热: <s:url id="url" value="/hello.action" />
@ZXJ~佳: 加了以后$.post好像就不执行了 虽然没报错但是功能也没调用
@脑热: 设置个断点看看有没有到后台
@ZXJ~佳: 确实没执行 post里面的alert没有提醒
$.post(url, args, function(data) {
alert(url);
if (data == "1") {
$this.after("<font color='green'>lastName可用</font>");
} else if (data == "0") {
$this.after("<font color='red'>lastName不可用</font>");
} else {
alert("服务器错误");
}
});
@脑热: 不是这里,我说的是你java后台
@ZXJ~佳: 没有诶 什么反应都没有
无法.......