All help me!
when i restart Tomcat5.0 after a day, it will happen "StackOverflowError"!
if i do not use Threadlocal,mybe it is OK!(do not affirm) why?
I use:
LINUX(REDHAD 8.0)
J2SDK 1.4.2_04
hibernate 2.14 2.13 2.12
tomcat 5.024 5.025 5.026
mysql 4.0
JDBC : mysql driver 3.07 stable
1.SessionBean.java
package com.yours.admin.web;
import java.util.List;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class SessionBean {
//是否已经登录
private boolean isLogon;
private UserActionForm userActionForm;
private TeamActionForm teamActionForm;
private RoleActionForm roleActionForm;
private AuthActionForm authActionForm;
private java.util.List authList;
/**
* 取得登录状态
* @return boolean
*/
public boolean getIsLogon() {
return isLogon;
}
/**
* 设置登录状态
* @param isLogon boolean
*/
public void setIsLogon(boolean isLogon) {
this.isLogon = isLogon;
}
/**
*
* @return UserActionForm
*/
public UserActionForm getUserActionForm() {
return userActionForm;
}
/**
*
* @param userActionForm UserActionForm
*/
public void setUserActionForm(UserActionForm userActionForm) {
this.userActionForm = userActionForm;
}
/**
*
* @return AuthActionForm
*/
public AuthActionForm getAuthActionForm() {
return authActionForm;
}
/**
*
* @param authActionForm AuthActionForm
*/
public void setAuthActionForm(AuthActionForm authActionForm) {
this.authActionForm = authActionForm;
}
/**
*
* @return RoleActionForm
*/
public RoleActionForm getRoleActionForm() {
return roleActionForm;
}
/**
*
* @param roleActionForm RoleActionForm
*/
public void setRoleActionForm(RoleActionForm roleActionForm) {
this.roleActionForm = roleActionForm;
}
/**
*
* @return TeamActionForm
*/
public TeamActionForm getTeamActionForm() {
return teamActionForm;
}
/**
*
* @param teamActionForm TeamActionForm
*/
public void setTeamActionForm(TeamActionForm teamActionForm) {
this.teamActionForm = teamActionForm;
}
/**
*
* @return List
*/
public java.util.List getAuthList() {
return authList;
}
/**
*
* @param authList List
*/
public void setAuthList(java.util.List authList) {
this.authList = authList;
}
}
3.SetEncodingFilter
package com.iclass.util;
import com.yours.datamodel.hibernate.HibernateSession;
/**
*
* <p>Description: 解决汉字编码问题</p>
* <p>自动关闭 Hibernate Session</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: 信息中心</p>
* @author 段洪杰
* @version 1.0
*/
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import net.sf.hibernate.HibernateException;
import org.apache.log4j.Logger;
public class SetEncodingFilter
implements Filter {
private static Logger log = Logger.getLogger(SetEncodingFilter.class);
protected String encoding = null;
protected FilterConfig filterConfig = null;
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
}
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
try {
// Set Character Encoding
request.setCharacterEncoding(this.encoding);
chain.doFilter(request, response);
}
finally {
// commit transaction and close hibernate session
try {
HibernateSession.commitTransaction();
}
catch (HibernateException e) {
try {
HibernateSession.rollbackTransaction();
}
catch (HibernateException e1) {}
log.error(e);
}
finally {
try {
// close Hibernate Session
HibernateSession.closeSession();
}
catch (HibernateException e) {
log.error(e);
}
}
}
}
}
3.dao
package com.yours.admin.dao;
import java.util.List;
import java.util.Iterator;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import org.apache.log4j.Logger;
import com.yours.admin.jdo.Auth;
import com.yours.datamodel.hibernate.*;
/**
* <p>Title: DAO</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author 段洪杰
* @version 1.0
*/
public class AuthDAOImpl implements AuthDAO{
private static Logger log = Logger.getLogger(AuthDAOImpl.class);
/**
* 增加记录
* @param auth Auth
*/
public void setAuth(Auth auth){
try {
Session session = HibernateSession.currentSession();
HibernateSession.currentTransaction();
session.save(auth);
session.flush();
}
catch (HibernateException e) {
log.error(e);
}
}
/**
* 通过ID取得记录
* @param id String
* @return Auth
*/
public Auth getAuthById(String id){
try {
Session session = HibernateSession.currentSession();
return (Auth) session.load(Auth.class, id);
}
catch (HibernateException e) {
log.error(e);
return null;
}
}
/**
* 修改记录
* @param Auth auth
*/
public void modifyAuth(Auth auth){
try {
Session session = HibernateSession.currentSession();
HibernateSession.currentTransaction();
session.update(auth);
session.flush();
}
catch (HibernateException e) {
log.error(e);
}
}
/**
* 删除记录
* @param Auth auth
*/
public void removeAuth(Auth auth){
try {
Session session = HibernateSession.currentSession();
HibernateSession.currentTransaction();
session.delete(auth);
session.flush();
}
catch (HibernateException e) {
log.error(e);
}
}
/**
* 取记录总数
* @return int
*/
public int getAuthsCount(){
int count = 0;
try {
Session session = HibernateSession.currentSession();
count = ( (Integer) session.iterate("select count(*) from Auth").next()).intValue();
}
catch (HibernateException e) {
log.error(e);
}
return count;
}
/**
* 取记录集合
* @return Iterator
* @param int position, int length
*/
public Iterator getAuths(int position, int length){
Iterator iterator=null;
String queryString =" select auth from Auth as auth order by auth.id desc";
try {
Session session = HibernateSession.currentSession();
//创建查询
Query query = session.createQuery(queryString);
//设置游标的起始点
query.setFirstResult(position);
//设置游标的长度
query.setMaxResults(length);
//记录生成
List list = query.list();
//把查询到的结果放入迭代器
iterator = list.iterator();
}
catch (HibernateException e) {
log.error(e);
}
return iterator;
}
}
4. struts-actionBean
package com.yours.admin.web;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.Date;
import com.yours.admin.dao.AuthDAO;
import com.yours.admin.dao.AuthDAOFactory;
import com.yours.admin.dao.AuthDAOImpl;
import com.yours.admin.map.AuthMap;
import com.yours.admin.jdo.Auth;
import org.apache.log4j.Logger;
import com.yours.admin.tree.TreeAuthFacade;
public class SetAuthAction extends Action {
private static Logger log = Logger.getLogger(SetAuthAction.class);
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
AuthActionForm authActionForm = (AuthActionForm) actionForm;
AdminSessionBean adminSessionBean = (AdminSessionBean) httpServletRequest.getSession().getAttribute("adminSessionBean");
if (adminSessionBean == null) {
httpServletRequest.setAttribute("message", "系统超时,请返回!");
httpServletRequest.setAttribute("locationFile","history.go(-2);");
return actionMapping.findForward("message");
}
if (!adminSessionBean.getIsLogon()) {
httpServletRequest.setAttribute("message", "没有登录!");
httpServletRequest.setAttribute("locationFile","location='adminLogon.jsp';");
return actionMapping.findForward("message");
}
String backURL=httpServletRequest.getHeader("Referer");
////////////数据入库////////////
AuthDAO authDAO = null;
Auth auth = null;
try {
authDAO = AuthDAOFactory.getAuthDAO();
auth= new AuthMap().getAuth(authActionForm);
auth.setCreatedate(new Date());
authDAO.setAuth(auth);
new TreeAuthFacade().createAuthTreeJavaScript(httpServletRequest.getRealPath("/admin"));
}
catch (Exception ex) {
log.error(ex);
}
httpServletRequest.setAttribute("message", "录入完成!");
httpServletRequest.setAttribute("locationFile","location='"+backURL+"';");
return actionMapping.findForward("message");
}
}
4.Struts-plusIn
package com.iclass.plugin;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import javax.servlet.ServletException;
import org.apache.log4j.Logger;
import com.iclass.filtrate.Filtrate;
public class InitFiltrate implements PlugIn {
private static Filtrate filtrate=new Filtrate();
private static Logger log = Logger.getLogger(InitFiltrate.class);
private String fileName;
/**
*
* @param servlet ActionServlet
* @param config ModuleConfig
* @throws ServletException
*/
public void init(ActionServlet servlet, ModuleConfig config) throws
ServletException {
try {
String realFileName = servlet.getServletContext().getRealPath(fileName);
filtrate.setFileName(realFileName);
}
catch (Exception ex) {
log.error(ex+" 初始化Filtrate时出错!\r\n");
}
}
/**
*
*/
public void destroy() {
filtrate = null;
}
/**
*
* @return Filtrate
*/
public static Filtrate getFiltrate() {
return filtrate;
}
/**
*
* @return String
*/
public String getFileName() {
return fileName;
}
/**
*
* @param fileName String
*/
public void setFileName(String fileName) {
this.fileName = fileName;
}
}
|