Struts2 自定义Result-Type 实现跳转页面是弹出提示框
来源:互联网 发布:windows oracle主备 编辑:程序博客网 时间:2024/05/19 20:42
Struts自带的resulttype类型只能直接跳转到制定页面或action,如果想实现跳转是弹出提示框,类似于使用Servlet的时,利用response往页面打印js实现弹提示框与跳转
response.getWriter().print("<script>alert('提示信息!');location.href='跳转地址'</script>");
那么我们可以自定义一个Resulttype类型,来实现这个效果
- 首先创建一个类,继承自ServletRedirectResult
- 这个类是我查看struts源码,反正struts自带的redirect类型所对应的类就是这个类,那么我们可以继承这个类,然后重写其中的跳转方法
- 重写方法:sendRedirect
@Override protected void sendRedirect(HttpServletResponse response, String finalLocation) throws IOException { response.setContentType("text/html;charset=utf-8"); response.getWriter().print("<script>alert('提示信息!');location.href='跳转地址'</script>"); }
- 在struts配置文件里添加自定义的result-type
<result-types> <result-type name="mytype" class="test.MyResultType"></result-type></result-types>
- 那么我们在跳转的时候,在结果里就可以使用我们新建的result-type
<action name="test"> <result type="mytype">index.jsp</result></action>
- 但是我们这样写的话,弹出的提示信息无法改变,那么可以通过定义result-type的参数来将提示信息传递进去
- 那么首先去MyResultType里定义一个msg来存储消息
<action name="test"> <result type="mytype"> <param name="location">index.jsp</param> <param name="msg">提示消息!</param> </result></action>
private String msg; @Override protected void sendRedirect(HttpServletResponse response, String finalLocation) throws IOException { response.setContentType("text/html;charset=utf-8"); response.getWriter().print("<script>alert('"+msg+"');location.href='跳转地址'</script>"); } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; }
OK,我们可以实现struts跳转弹窗了!!
0 0
- Struts2 自定义Result-Type 实现跳转页面是弹出提示框
- struts2 result type页面跳转方式介绍
- struts2自定义result中的type
- struts2中result的type跳转类型
- struts2中result的type跳转类型
- struts2中result的type跳转类型
- servlet弹出提示框并跳转页面
- 弹出提示框,并且进行页面跳转
- 实现页面session验证,非法用户将弹出提示框并跳转页面
- 在servlet中实现弹出提示框,点击确认后跳转其他页面
- struts2 跳转类型 result type=chain、dispatcher、redir
- struts2跳转类型result type=chain/dispatcher/redirect
- struts2中result的type跳转类型总结
- 操作完成后弹出提示框,然后跳转页面
- 用VBScript弹出提示框然后跳转到指定页面
- asp.net 后台代码跳转页面前弹出提示框
- EasyUI实现页面右下角弹出提示框
- Servlet 页面跳转 并弹出提示对话框
- 第一博
- Linux Error: 11: Resource temporarily unavailable
- iOS - IM环信集成
- oracle em 按钮乱码现象
- Oracle导出where条件内容
- Struts2 自定义Result-Type 实现跳转页面是弹出提示框
- 彻底解决 LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- linux安装中文方块乱码现象
- mysql中文字符的问题
- [绍棠] ios资源汇总
- windows2008r2环境双实例安装mysql5.6
- oracle数据库的ora_p进程为什么这…
- java Jdbc连接oracle数据库连接测…
- 如何对时间函数进行加减