It didn't work for me until I realized that the error was the web.xml order.
Here is my web.xml working
<web-app>
<display-name>F.A.Na</display-name>
<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Session filter -->
<filter>
<filter-name>smFilter</filter-name>
<filter-class>fana.filter.SessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>smFilter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Usual Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/tags/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-nested</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/struts-tiles</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
</web-app>
servlet-mapping and filter tags were upside-down and Tomcat didn't startup the application
Here is my SessionFilter class
public class SessionFilter implements Filter {
private SessionFactory factory;
public void init(FilterConfig cfg) throws ServletException {
factory = new Configuration().configure().buildSessionFactory();
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
Session session = factory.openSession();
request.setAttribute("hibernate.session", session);
System.out.println("Placing session in request from SessionFilter!");
try {
chain.doFilter(request, response);
}
finally {
if ((session != null) && (session.isOpen())) {
System.out.println("Closing session!");
session.close();
}
}
}
public void destroy() {}
}
Hope this helps anyone. I think it's a very simple way to keep a session alive during jsp's.[/code]
|