老大,你先搞清楚什么是javabean在说!

解决方案 »

  1.   

    javaBean就是一个类嘛,难道真的不能再里面实现跳转到某个jsp的操作,为啥子呢?
    我现在在一个bean中有个监听session的函数,想等session消亡的时候跳转到别的页面该怎么操作
      

  2.   

    把当前HttpServletResponse作为参数传过去。
      

  3.   

    不行三,valueUnbound函数的参数是固定的,传过来就不行,在函数里面new一个好像也不行。
    怎么办
      

  4.   

    我需要用到监听函数哦
    用servlet的话public class GetPoolServlet  extends HttpServlet 
    那么implements HttpSessionBindingListener放哪里呢
      

  5.   

    可以这样写啊
    public class GetPoolServlet extends HttpServlet implements HttpSessionBindingListener
      

  6.   

    javaBean就是一个类嘛,难道真的不能再里面实现跳转到某个jsp的操作,为啥子呢?
    我现在在一个bean中有个监听session的函数,想等session消亡的时候跳转到别的页面该怎么操作
    怎么实现啊?贴出源代码大家分享一下!
      

  7.   

    但是还是没有解决我原先的问题啊,我想在session消亡的时候,在监听函数中执行页面跳转
    response.sendRedirect("OutOfTime.jsp");  在监听函数中不能直接用啊
      

  8.   

    我就是用servlet啊,我在servlet中用valueUnbound这个监听函数,如果在这个函数中执行页面跳转呢?又不能传入HttpServletResponse参数。
    是不是我的处理方法不对啊
      

  9.   

    class bean是不能跳转的,他主要是处理数据、业务逻辑等。如果要跳转的话,要在jsp或servlet中根据bean处理结果选择是否跳转。
      

  10.   

    public class GetPoolServlet  extends HttpServlet implements HttpSessionBindingListener{
      private static final String CONTENT_TYPE = "text/html; charset=GBK";
      private DBConnectionManager connMgr=null;
        boolean connFlag;
        String logname,password,userip,
               message=""; //用来返回登录是否成功的消息。
        String loginorout="";   //登录还是注销登录的标记,0为登录,1为注销
        Date intime=new Date(),outtime=new Date();
        Connection con=null;
        Statement sql=null;
        ResultSet rs=null;
        char sign[]={(char)0x02,(char)0x01};
        String unisign=new String(sign);
        public void setConnMgr(DBConnectionManager connMgr){
            this.connMgr=connMgr;
        }
        public void valueBound(HttpSessionBindingEvent event) {     //session创建时候的监听函数
          int test1=9;
          int test2=8;
      }
      public void valueUnbound(HttpSessionBindingEvent event ) {      //session消亡时候的监听函数,此时向数据库更新数据(更新退出时间)
          //这个时候该Bean中的变量值不会消失,因为变量的生命期是这个Bean,而session开始和注销函数都在这里,那么变量的生命周期自然延长到了session结束位置
          connFlag=false;
          try{
              if(logname!=null&&logname!=""){
                outtime = new Date();
                con = connMgr.getConnection("bookcase");
                if (con == null) {
                  return;
                }
                sql = con.createStatement();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String condition = "UPDATE PC_LOGIN SET UoutTime='" +
                    sdf.format(outtime) + "' WHERE UserID = '" + logname +
                    "' AND UinTime='" + sdf.format(intime) + "'";
                sql.executeUpdate(condition);
              }
              
              response.sendRedirect("OutOfTime.jsp");       //就是想这样确不能啊
          }
          catch( SQLException e ){
              if(e.getErrorCode()==0)connFlag=true;   //如果连接坏了,比如网线被拔掉,不这样的话如果真的有意思坏了就会把坏的东西还给连接池子
          }
          catch(Exception e){
          }
          finally{
              try{
                  if(rs!=null)rs.close();
                  if(sql!=null)sql.close();
              }
          catch(Exception ignore){}
          }
          if(con!=null){     //如果连接还存在则放入连接池,如果连接断了则通过异常放入专门的地方
              connMgr.freeConnecton("bookcase", con,connFlag);           //
          }  }
      //Initialize global variables
      public void init() throws ServletException {
          super.init();
          connMgr = DBConnectionManager.getInstance();
      }  //Process the HTTP Get request
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String retujsp=request.getParameter("retujsp");   //取得最终要返回得页面
        if(retujsp!=null){
          HttpSession session = request.getSession();
          session.setMaxInactiveInterval(60);
          session.setAttribute("MyconnMgr", connMgr);   //将连接池句柄放入session,以后所有得Jsp都可以直接从session中获取该句柄了
          //RequestDispatcher dispatcher =
          //getServletContext().getRequestDispatcher("http://localhost:8080/myapp/JSP/"+retujsp);
          //dispatcher.forward(request, response);
          //response.setConresponse.stentType(CONTENT_TYPE);
        //response.sendRedirect("http://localhost:8080/myapp/jsp/IniJsp.jsp");
        response.sendRedirect("http://localhost:8080/myapp/yk_jsp/IniJsp.jsp");
        }
      }
      //Clean up resources
      public void destroy() {
          connMgr.release();
          super.destroy();
      }
    }
      

  11.   

    有两方法:
    1、就是转向后要返回当前页面继续执行:
    <jsp:include page="页面" flush="true"/>
    2.转向某一页面不返回:
    <jsp:forward page="页面"/>
      

  12.   

    把监听函数写在javabean里,在servlet里通过传递参数调用javabean里的监听函数
    顺便问一句,上面程序运行结果出现的是什么错误
      

  13.   

    楼上的能不能说具体点,如何在servlet中调用javabean的监听函数?