ReturnTo.java
package examples;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
/*
自动转向javabean
*/
public class ReturnTo extends HttpServlet
{
PRivate String Msg;
private String Rurl;
private boolean isA;
public void setMsg(String inMsg) {
this.Msg=inMsg;
}
public void setRurl(String inRurl){
this.Rurl=inRurl;
}
public void setIsA(boolean inisA){
this.isA=inisA;
}
public String getMsg() {
return this.Msg;
}
public String getRurl() {
return this.Rurl;
}
public boolean getIsA() {
return this.isA;
}
public void go(HttpServletResponse response) throws IOException, ServletException {
PrintWriter out = response.getWriter();
out.print("<script language='Javascript'>");
if (this.isA) {
out.print("alert('"+ Msg + "!');");
}
out.print("location.href='"+Rurl+"';");
out.print("</script>");
}
}
应用test.jsp
<%@ page contentType="text/Html;charset=GBK"%>
<jsp:useBean id="we" scope="page" class="com.china3cts.common.ReturnTo" />
<%
String Msg="自动转向中....";
String Url="http://www.java3z.com";
we.setMsg(Msg);
we.setRurl(Url);
we.setIsA(true);
we.go(response);
%>
注释说明:
1:保存文件位置
ReturnTo.class ===>web-inf/classes/examples/
test.jsp 任意位置
2,写这个主要是不想页面上出现太多的javascript代码:) 纯粹无聊.
3,测试在tomcat + jdk1.5 + win2k3 下通过.
新闻热点
疑难解答