Problema com filter web.xml [RESOLVIDO]

8 respostas
L

Galera,to fazendo um filter para poder validar se o usuário esta logado ou não caso ele tente acessar as paginas pela url, o problema é que não consigo fazer o web.xml "reconhecer" meu diretório,pelo menos é oque eu acho que esta acontecendo, vou postar aqui a minha classe login e o web.xml para vocês darem uma olhada:

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,ServletException{
            HttpSession session=((HttpServletRequest)req).getSession();
            String codigo=(String)session.getAttribute("id");
            if(codigo==null){
                ((HttpServletResponse)res).sendRedirect("/faces/login.xhtml");
            }
            else{
                chain.doFilter(req, res);
            }
        }
    
        public void destroy(){
            throw new UnsupportedOperationException("Not supported yet");
        }
        
        public void init(FilterConfig arg0) throws ServletException{
            throw new UnsupportedOperationException("Not supported yet");
        }

e aqui ta o web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/login.xhtml</welcome-file>
    </welcome-file-list>
    
    <filter>
       <filter-name>FiltroSeguranca</filter-name>
       <filter-class>dao.LoginDAO</filter-class>
    </filter>
    
    <filter-mapping>
       <filer-name>FiltroSeguranca</filer-name>
       <url-pattern>/faces/*</url-pattern>
    </filter-mapping>
    
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>redmond</param-value>
    </context-param>
    
</web-app>

O projeto simplesmente não compila, mas se eu tirar esse trecho do filter-mapping o projeto compila mas obviamente não funciona o filtro.Vi aqui no forum e também em outros foruns a configuração do web.xml e estão todos iguais ao meu,mas porque o meu não funciona?

8 Respostas

T

Olá Luciano…

Aparece alguma mensagem de erro, algo no console quando vc compila?
tem como colocar aqui?

A

Ao iniciar a aplicação está sendo lançada uma execeção aqui:

public void init(FilterConfig arg0) throws ServletException{  
     throw new UnsupportedOperationException("Not supported yet");  
 }

Esse init() é chamado quando a aplicação inicia. Tenta comentar esse “throw”.

Isso tá com cara do código gerado pelo netbeans.

L
deploy?DEFAULT=/home/luciano/NetBeansProjects/projeto/build/web&name=projeto&force=true falhou em GlassFish Server 3.1 
 Erro durante a implementação: Exceção ao implementar o aplicativo [projeto] : org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'filer-name'. One of '{"http://java.sun.com/xml/ns/javaee":filter-name}' is expected.. Consulte o server.log para obter mais detalhes
/home/luciano/NetBeansProjects/projeto/nbproject/build-impl.xml:727: 
O módulo não foi implementado.
	at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:187)
	at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:106)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
	at sun.reflect.GeneratedMethodAccessor131.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.Target.execute(Target.java:390)
	at org.apache.tools.ant.Target.performTasks(Target.java:411)
	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
	at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
	at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
	at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284)
	at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
	at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:154)
FALHA NA CONSTRUÇÃO (tempo total: 0 segundos)
T

Bao seria Filter no lugar do Filer???

FiltroSeguranca /faces/*
L

tiago.javaman:
Bao seria Filter no lugar do Filer???

FiltroSeguranca /faces/*


Meu Deus O.o

T

A mensagem de erro no console estava clara. hehehe

Acontece :lol:

L

Rodou só que o filter não funciona :frowning:

T

ayslanms:

Ao iniciar a aplicação está sendo lançada uma execeção aqui:

public void init(FilterConfig arg0) throws ServletException{  
     throw new UnsupportedOperationException("Not supported yet");  
 }

Esse init() é chamado quando a aplicação inicia. Tenta comentar esse “throw”.

Isso tá com cara do código gerado pelo netbeans.

Verifique o que o ayslanms comentou aqui.

Criado 12 de julho de 2011
Ultima resposta 12 de jul. de 2011
Respostas 8
Participantes 3