-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SessionFilter with Struts to leep session alive in jsp
PostPosted: Wed Aug 16, 2006 9:44 am 
Newbie

Joined: Wed Aug 16, 2006 9:35 am
Posts: 2
Location: Buenos Aires, Argentina
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]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.