1 pièce(s) jointe(s)
Appliquer un filtre a une page JSP précise
Bonjour ,
J'ai une question a propos des filters en JEE , en fait je veux exécuter mon filter qui affiche la liste des clients même si la session des clients est null , mais cela juste dans une seule page situé dans le WEB-INF de l'application et pas dans toute l'application (<url-pattern>/*</url-pattern>) , j'ai testé dans le web.xml plusieurs url , dans le <url-pattern> , la page s'affiche mais le filter ne s’exécute pas sur la page .
Voila mon web.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SiteWeb</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>MapFilter</filter-name>
<filter-class>com.tomo.filter.MapFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MapFilter</filter-name>
<url-pattern>/list_tomodachi.jsp</url-pattern>
</filter-mapping>
</web-app> |
Voila mon filter MapFilter :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
package com.tomo.filter;
public class MapFilter implements Filter {
private static final String sessionTomodachi = "TomodachiSession";
private TomodachiDAO tomodachiDAO;
public static final String InisialDaoFactory = "daoFactory";
public MapFilter() {
// TODO Auto-generated constructor stub
}
public void doFilter( ServletRequest req, ServletResponse res, FilterChain chain ) throws IOException,
ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpSession session = request.getSession();
if ( session.getAttribute( sessionTomodachi ) == null ) {
ArrayList<Tomodachi> listeTomo = tomodachiDAO.listTomodachi();
Map<Long, Tomodachi> mapTomo = new HashMap<Long, Tomodachi>();
for ( Tomodachi tomodachi : listeTomo ) {
mapTomo.put( tomodachi.getId_tomodachi(), tomodachi );
}
session.setAttribute( sessionTomodachi, mapTomo );
}
chain.doFilter( request, res );
}} |
Et voila arborescence de mon application :