现在的位置: 首页 > 综合 > 正文

一个网站转向的JavaBean

2013年10月01日 ⁄ 综合 ⁄ 共 1237字 ⁄ 字号 评论关闭

以下是java源码ReturnTo.java

package com.lzpc.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.lzpc.common.ReturnTo" />
<%
String Msg="网站正在转向中,请稍等";
String Url="http://www.lzpc.net/";
we.setMsg(Msg);
we.setRurl(Url);
we.setIsA(true);
we.go(response);
%>

注释说明:

1:保存文件位置

ReturnTo.java ===>tomcat5.8/webapps/ROOT/WEB-INF/classes/com/lzpc/common

test.jsp 放到tomcat5.8/webapps/ROOT下,

2,写了这个Bean在运用网站转向时就不用写这么多的javascript代码:)

3,在tomcat5.8 + jdk1.5 + winXP 下测试通过.
 

抱歉!评论已关闭.