天天看点

Struts2__action中实现先弹窗再跳转

HttpServletResponse response = ServletActionContext.getResponse();

response.setContentType("text/html;charset=UTF-8");

response.setCharacterEncoding("UTF-8");//防止弹出的信息出现乱码

PrintWriter out = null;

try {

    out = response.getWriter();

    out.print("<script>alert('抱歉,您的链接已失效,您可以返回首页重新申请')</script>");

    out.print("<script>window.location.href='/index.action'</script>");

    out.flush();

    out.close();

} catch (IOException e) {

    e.printStackTrace();

}

附:

if(***){//表单提交

     PrintWriter out = null;

     try {

     out = response.getWriter();

     out.println(Items);//可以是一个自动提交的表单

     out.flush();

     out.close();

     } catch (IOException e) {

     // TODO Auto-generated catch block

     e.printStackTrace();

     }

    }else{

      response.sendRedirect(Items);//url地址发送

    }

return null;

本文转自 艺晨光 51CTO博客,原文链接:http://blog.51cto.com/ycgit/1621392,如需转载请自行联系原作者

继续阅读