网站导航:首页 -> JAVA认证 -> Java认证公共基础知识复习资料 -> 自动转向的javabean源码

自动转向的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 下通过.