cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package cn.ksource.core.util;
 
import java.io.PrintWriter;
 
import javax.servlet.http.HttpServletResponse;
 
public class ScriptUtil {
 
    private static void doAlert(HttpServletResponse response,String script){
        try {
            response.setContentType("text/html");
            response.setCharacterEncoding("gbk");
            PrintWriter writer = response.getWriter();
            writer.print(script);
            writer.flush();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    /**
     * 功能描述:在客户端生成一个alert,并将当前页面转向指定的path<BR>
     * @param alert 要警告的话
     * @param path 转向路径
     * @return
     * @author:杨凯<BR>
     * 时间:Mar 3, 2009 11:33:26 PM<BR>
     */
    public static void alertAnd2Url(HttpServletResponse response,String alert,String path){
        String script = "<script>alert('"+ alert +"');location.href='"+path+"'</script>";
        doAlert(response, script);
    }
    
    /**
     * 功能描述:在客户端生成Alert,并将指定的窗口,导向指定的地址<BR>
     * @param response
     * @param window
     * @param alert
     * @param path
     * @author:杨凯<BR>
     * 时间:Jun 4, 2009 4:57:46 PM<BR>
     */
    public static void alertAnd2Url(HttpServletResponse response,String window,String alert,String path){
        String script = "<script>alert('"+ alert +"');"+window+".location.href='"+path+"'</script>";
        doAlert(response, script);
    }
    
    /**
     * 功能描述:将页面导向指定的URL<BR>
     * @param response
     * @param path
     * @author:杨凯<BR>
     * 时间:Jun 4, 2009 5:04:46 PM<BR>
     */
    public static void goUrl(HttpServletResponse response,String path){
        String script = "<script>location.href='"+path+"'</script>";
        doAlert(response, script);
    }
    
    /**
     * 功能描述:在客户端生成一个alert<BR>
     * @param alert
     * @return
     * @author:杨凯<BR>
     * 时间:Jun 4, 2009 11:15:06 AM<BR>
     */
    public static void alert(HttpServletResponse response,String alert){
        String script = "<script>alert('"+ alert +"');</script>";
        doAlert(response, script);
    }
    
    /**
     * 功能描述:在客户端生成一个alert,并将页面后退<BR>
     * @param alert
     * @return
     * @author:杨凯<BR>
     * 时间:Mar 23, 2009 3:08:41 PM<BR>
     */
    public static void alertAndGoBack(HttpServletResponse response,String alert){
        String script = "<script>alert('"+ alert +"');history.go(-1);</script>";
        doAlert(response, script);
    }
    
    public static void doScript(HttpServletResponse response, String scriptString) {
        String script = "<script type=\"text/javascript\">"+ scriptString +"</script>";
        doAlert(response, script);
    }
}