老大,你先搞清楚什么是javabean在说!
解决方案 »
- artDialog Error: document.compatMode === "BackCompat"
- 求二级动态下拉列表设计方法 JavaWeb
- jQuery文件上传 带进度条 控件
- source not found(tomcat运行时)
- java 工程师招聘
- 选择JSP的理由?
- 如何在数据库有新数据时就立即告知客户端
- 关于sshe web项目错误 syntax error, expect RPAREN, actual UNIQUE unique
- DreamWeaver里下拉列表有两种选择:list,menu,请问这两者什么区别?
- 有那位热心的高手能提供一些tapestry的资料感激不尽!
- 请教高手
- 一个关于session的问题,帮帮俺行吗
我现在在一个bean中有个监听session的函数,想等session消亡的时候跳转到别的页面该怎么操作
怎么办
用servlet的话public class GetPoolServlet extends HttpServlet
那么implements HttpSessionBindingListener放哪里呢
public class GetPoolServlet extends HttpServlet implements HttpSessionBindingListener
我现在在一个bean中有个监听session的函数,想等session消亡的时候跳转到别的页面该怎么操作
怎么实现啊?贴出源代码大家分享一下!
response.sendRedirect("OutOfTime.jsp"); 在监听函数中不能直接用啊
是不是我的处理方法不对啊
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();
}
}
1、就是转向后要返回当前页面继续执行:
<jsp:include page="页面" flush="true"/>
2.转向某一页面不返回:
<jsp:forward page="页面"/>
顺便问一句,上面程序运行结果出现的是什么错误