xiekun1103 2017-02-17 13:13 采纳率: 50%
浏览 1053

如何从JavaScript跳转到struts的result中?

环境:jdk1.6、ssh2、ext-4.1.1a
代码片段:
// 以Ajax方式提交表单
form.submit({
// 提交成功,第一个参数是Ext.form.Basic对象
// 第二个参数是Ext.action.Action对象
success : function(form, action) {
Ext.Msg.alert('登录成功!',
action.result.msg);
window.location.href="customerLogon.action?result=success";
},
// 提交失败
failure : function(form, action) {
Ext.Msg.alert('登录失败!',
action.result.msg);
}
});

public void logon() throws Exception {
boolean result = userService.find(user);
Map result2 = new HashMap();
if (result) {
result2.put("success", true);
result2.put("msg", "恭喜你,登录成功!");
} else {
result2.put("success", false);
result2.put("msg", "对不起,您的用户名、密码不匹配!");
}
// 准备输出服务器响应
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
// 将Map包装成JSONObject后输出
out.print(new JSONObject(result2));
}


method="logon">
<!-- 成功 -->
/loginSuccess.jsp
<!-- 失败 -->
/loginFail.jsp


现在表单可以提交成功,输出下面这个,页面跳转失败:
严重: Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'result' on 'class net.action.UserAction: Error setting expression 'result' with value ['success', ]
就是如何用window.location.href跳转到result中去?用其它方式也可以 ,就是不要直接跳转到jsp页面,我要用struts.xml来控制页面跳转。能不能直接在logon()中更改达到同样的效果?如何实现?

已经找到办法,可以实现,不过这样相当麻烦,性能有点低,只能用于小项目。
关键代码:
public Map test() throws Exception {
ActionContext context = ActionContext.getContext();
ActionInvocation invocation = context.getActionInvocation();
ActionProxy proxy = invocation.getProxy();
ActionConfig config = proxy.getConfig();
Set> entrySet = config.getResults()
.entrySet();
Map res = new HashMap();
for (Map.Entry entry : entrySet) {
Map map = entry.getValue().getParams();
Set paramSet = map.entrySet();
for (Map.Entry e : paramSet) {
System.out.println(entry.getKey() + "=" + e.getValue());
res.put(entry.getKey(), (String) e.getValue());
}
}
return res;
}
不过没有完全解决,输出的是:
success=/loginSuccess.jsp
error=/loginFail.jsp
理想中:Map> map,每个Map应该用一个action中class字符串来区别,这样如何实现?麻烦大神帮我改上面代码。谢谢!

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-02-17 15:36
    关注

    这样当然不行,js可以用windows.location.href=地址; 的办法跳转

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题