java web session监听器的问题

时间:2022-11-18 22:43:26
java类:
LoginListener 实现 HttpSessionListener接口
package com.orderMeal.util;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import com.orderMeal.bean.SysUser;
import com.orderMeal.exception.DaoException;
import com.orderMeal.zjc.service.ISysUserService;
public class LoginListener implements HttpSessionListener {
     
private ISysUserService userService;//注入ISysUserService
public void setUserService(ISysUserService userService) {
this.userService = userService;
}
public ISysUserService getUserService()
{
ApplicationContext act = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/Spring/applicationContext-zjc.xml"); 
userService = (ISysUserService)act.getBean("sysUserService");
return userService;
}
public void sessionCreated(HttpSessionEvent arg0) 
{
}
public void sessionDestroyed(HttpSessionEvent hse) 
{
System.out.println("-------监听器--------");
SysUser users = (SysUser)hse.getSession().getAttribute("sysUser");
System.out.println(users.getSysUserName());
users.setSysState(0);//将状态设为0
System.out.println("ssss" + userService);
try {
getUserService().updateSysUser(users);
} catch (DaoException e) {
e.printStackTrace();
}
hse.getSession().removeAttribute("sysUser");
}
}
web.xml配置:
 <!-- 监听器 -->
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <!-- 监听器配置 -->
  <listener>
      <listener-class>com.orderMeal.util.LoginListener</listener-class>
  </listener>

spring 配置:
       我们项目是4个人做的,有4个spring配置,加载时我只调用了我的spring,可是当我点击后台退出时调用DispatchAction中的:
          /** 
 * Method execute 用户注销
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward doExit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
SysUser sysUser=(SysUser)request.getSession().getAttribute("sysUser");
sysUser.setSysState(0);
try {
sysUserService.updateSysUser(sysUser);
} catch (DaoException e) {

e.printStackTrace();
}
request.getSession().invalidate();
return mapping.findForward("loginFail");
}
后台就会会发生错误:
2010-6-9 16:13:41 org.apache.catalina.session.StandardSession expire
严重: Session event listener threw exception
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [C:\JavaSoft\Tomcat\tomcat6\bin\WebRoot\WEB-INF\Spring\applicationContext-zjc.xml]; nested exception is java.io.FileNotFoundException: WebRoot\WEB-INF\Spring\applicationContext-zjc.xml (系统找不到指定的路径。)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:80)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:422)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at com.orderMeal.util.LoginListener.getUserService(LoginListener.java:21)
at com.orderMeal.util.LoginListener.sessionDestroyed(LoginListener.java:36)
at org.apache.catalina.session.StandardSession.expire(StandardSession.java:702)
at org.apache.catalina.session.StandardSession.expire(StandardSession.java:660)
at org.apache.catalina.session.StandardSession.invalidate(StandardSession.java:1111)
at org.apache.catalina.session.StandardSessionFacade.invalidate(StandardSessionFacade.java:150)
at com.orderMeal.zjc.actions.SysUserListAction.doExit(SysUserListAction.java:166)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: WebRoot\WEB-INF\Spring\applicationContext-zjc.xml (系统找不到指定的路径。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
... 48 more




5 个解决方案

#1


[C:\JavaSoft\Tomcat\tomcat6\bin\WebRoot\WEB-INF\Spring\applicationContext-zjc.xml]; nested exception is java.io.FileNotFoundException: WebRoot\WEB-INF\Spring\applicationContext-zjc.xml (系统找不到指定的路径。)

#2


我的spring

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="/WEB-INF/hibernate.cfg.xml">
</property>
</bean>
<!-- 公共Dao -->
<bean id="BaseDao" class="com.orderMeal.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- ###################################数据持久层################################### -->
<bean id="foodDao" class="com.orderMeal.zjc.dao.FoodDaoImpl" parent="BaseDao"/>
<bean id="userDao" class="com.orderMeal.zjc.dao.UserDaoImpl" parent="BaseDao"/>
<bean id="comboDao" class="com.orderMeal.zjc.dao.ComboDaoImpl" parent="BaseDao"/>
<bean id="sysUserDao" class="com.orderMeal.zjc.dao.SysUserDaoImpl" parent="BaseDao"/>
<!-- 业务逻辑层 -->
<bean id="foodService" class="com.orderMeal.zjc.service.FoodServiceImpl">
<property name="foodDao">
<ref bean="foodDao"/>
</property>
</bean>
<bean id="userService" class="com.orderMeal.zjc.service.UserServiceImpl">
<property name="userDao">
<ref bean="userDao" />
</property>
</bean>
<bean id="comboService" class="com.orderMeal.zjc.service.ComboServiceImpl">
<property name="comboDao">
<ref bean="comboDao"/>
</property>
</bean>
<bean id="sysUserService" class="com.orderMeal.zjc.service.SysUserServiceImpl">
<property name="sysUserDao">
<ref bean="sysUserDao"/>
</property>
</bean>
<!-- 访问控制层 -->
<!-- 食物 ,菜谱-->
<bean name="/zjc/food" class="com.orderMeal.zjc.actions.FoodListAction">
<property name="foodService">
<ref bean="foodService"/>
</property>
</bean>
<!--普通 用户 -->
<bean name="/zjc/user" class="com.orderMeal.zjc.actions.UserListAction">
<property name="userService">
<ref bean="userService"/>
</property>
</bean>
<!-- 套餐 -->
<bean name="/zjc/combo" class="com.orderMeal.zjc.actions.ComboListAction">
<property name="comboService">
<ref bean="comboService"/>
</property>
<property name="foodService">
<ref bean="foodService"/>
</property>
</bean>
<!-- 酒店用户 -->
<bean name="/zjc/sysUser" class="com.orderMeal.zjc.actions.SysUserListAction">
<property name="sysUserService">
<ref bean="sysUserService"/>
</property>
<property name="foodService">
<ref bean="foodService"/>
</property>
</bean>
<bean id="loginListener" class="com.orderMeal.util.LoginListener">
   <property name="userService">
     <ref bean="sysUserService"/>
   </property>

</bean>

</beans>

#3


ApplicationContext act = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/Spring/applicationContext-zjc.xml");  

好好看看web应用怎样配置spring。

#4


可路径我搞了好长时间我真的不知道我写错那了!我是菜鸟请给大侠给个提示

#5


我搞好了,一直以来我都再搞整个项目的路径,后来才知道是服务器端的路径,不过还是要谢谢你们两位。。。现在我的监听器好了。。。多谢两位的提示,很高兴能为我答题

#1


[C:\JavaSoft\Tomcat\tomcat6\bin\WebRoot\WEB-INF\Spring\applicationContext-zjc.xml]; nested exception is java.io.FileNotFoundException: WebRoot\WEB-INF\Spring\applicationContext-zjc.xml (系统找不到指定的路径。)

#2


我的spring

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="/WEB-INF/hibernate.cfg.xml">
</property>
</bean>
<!-- 公共Dao -->
<bean id="BaseDao" class="com.orderMeal.dao.BaseDao">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- ###################################数据持久层################################### -->
<bean id="foodDao" class="com.orderMeal.zjc.dao.FoodDaoImpl" parent="BaseDao"/>
<bean id="userDao" class="com.orderMeal.zjc.dao.UserDaoImpl" parent="BaseDao"/>
<bean id="comboDao" class="com.orderMeal.zjc.dao.ComboDaoImpl" parent="BaseDao"/>
<bean id="sysUserDao" class="com.orderMeal.zjc.dao.SysUserDaoImpl" parent="BaseDao"/>
<!-- 业务逻辑层 -->
<bean id="foodService" class="com.orderMeal.zjc.service.FoodServiceImpl">
<property name="foodDao">
<ref bean="foodDao"/>
</property>
</bean>
<bean id="userService" class="com.orderMeal.zjc.service.UserServiceImpl">
<property name="userDao">
<ref bean="userDao" />
</property>
</bean>
<bean id="comboService" class="com.orderMeal.zjc.service.ComboServiceImpl">
<property name="comboDao">
<ref bean="comboDao"/>
</property>
</bean>
<bean id="sysUserService" class="com.orderMeal.zjc.service.SysUserServiceImpl">
<property name="sysUserDao">
<ref bean="sysUserDao"/>
</property>
</bean>
<!-- 访问控制层 -->
<!-- 食物 ,菜谱-->
<bean name="/zjc/food" class="com.orderMeal.zjc.actions.FoodListAction">
<property name="foodService">
<ref bean="foodService"/>
</property>
</bean>
<!--普通 用户 -->
<bean name="/zjc/user" class="com.orderMeal.zjc.actions.UserListAction">
<property name="userService">
<ref bean="userService"/>
</property>
</bean>
<!-- 套餐 -->
<bean name="/zjc/combo" class="com.orderMeal.zjc.actions.ComboListAction">
<property name="comboService">
<ref bean="comboService"/>
</property>
<property name="foodService">
<ref bean="foodService"/>
</property>
</bean>
<!-- 酒店用户 -->
<bean name="/zjc/sysUser" class="com.orderMeal.zjc.actions.SysUserListAction">
<property name="sysUserService">
<ref bean="sysUserService"/>
</property>
<property name="foodService">
<ref bean="foodService"/>
</property>
</bean>
<bean id="loginListener" class="com.orderMeal.util.LoginListener">
   <property name="userService">
     <ref bean="sysUserService"/>
   </property>

</bean>

</beans>

#3


ApplicationContext act = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/Spring/applicationContext-zjc.xml");  

好好看看web应用怎样配置spring。

#4


可路径我搞了好长时间我真的不知道我写错那了!我是菜鸟请给大侠给个提示

#5


我搞好了,一直以来我都再搞整个项目的路径,后来才知道是服务器端的路径,不过还是要谢谢你们两位。。。现在我的监听器好了。。。多谢两位的提示,很高兴能为我答题