江西广告网
标题:
自动转向的javabean源码
[打印本页]
作者:
与你同行
时间:
2008-12-30 11:16
标题:
自动转向的javabean源码
以下是java源码 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 下通过.
欢迎光临 江西广告网 (http://bbs.jxadw.com/)
Powered by Discuz! X3.2