天天看點

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,如需轉載請自行聯系原作者

繼續閱讀