• struts2的java文件中不能直接弹出script对话框


    需要引入接口

    ServletResponseAware
     1 public class Login extends ActionSupport implements SessionAware,ServletResponseAware
     2 {
     3         
     4     private HttpServletResponse response = null;
     5     ....
     6     public void setServletResponse(HttpServletResponse response) {
     7         // TODO Auto-generated method stub
     8         this.response = response;
     9     }
    10 
    11     public String execute()
    12     {
    13         Person person = new Person();
    14         PersonDAO personDAO = new PersonDAO();
    15         if(personDAO.findById(id)==null)
    16         {
    17             System.out.println("用户不存在");
    18             try {
    19                 response.setContentType("text/html; charset=UTF-8");
    20                 response.setCharacterEncoding("UTF-8");        //防止乱码;
    21                 PrintWriter out = response.getWriter();
    22                 out.print("<Script>alert('用户不存在!')</Script>");
    23                 out.flush();
    24                 out.close();
    25             }
    26             catch (IOException e) {
    27                 // TODO Auto-generated catch block
    28                 e.printStackTrace();
    29             }
    30         }
    31     ....
    32     } 
    33 }
    34             

    不过很多网页,像淘宝之类的,他们的页面出错不是这么处理的,这种方法弹出提示框以后不能再返回页面

  • 相关阅读:
    二叉树
    tomcat和jvm调优
    服务器正向代理
    LRU算法
    《转载》TCP三次握手中SYN,ACK,Seq三者的关系
    python的字符串、集合、for循环、异常等基础语法
    configparser_配置解析器
    hashlib模块
    悟_面向对象_小游戏和进阶
    面向对象_new,__eq__,__hash__
  • 原文地址:https://www.cnblogs.com/acm-bingzi/p/3682823.html
Copyright © 2020-2023  润新知