以下是java源码
ReturnTo.java
package com.china3cts.common;
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.3cts.com/";
we.setMsg(Msg);
we.setRurl(Url);
we.setIsA(true);
we.go(response);
%>
注释说明:
1:保存文件位置
ReturnTo.java ===>web-inf/classes/china3cts/common/
test.jsp 任意位置
2,写这个主要是不想页面上出现太多的javascript代码:) 纯粹无聊.
3,测试在tomcat + jdk1.5 + win2k3 下通过.