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);
|
}
|
}
|