Eclipse Não reconhece Filter

1 resposta
eclipsewebjspjava
C

Gente, boa noite. eu não sei se o problema está no eclipse ou no código.
o eclipse não está reconhecendo o filter que eu criei. O erro aparece no web.xml
segue o código abaixo

package filter;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import connection.SingleConnection;

@WebFilter(urlPatterns={"/*"})
public class Filter implements javax.servlet.Filter {
	
	@Override
	public void destroy() {
	
	}
	
	private static Connection connection;
	
	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {
		try {
			arg2.doFilter(arg0, arg1);
			connection.commit();
		} catch(Exception e) {
			try {
				connection.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		}
	}
	
	@Override
	public void init(FilterConfig arg0) throws ServletException {
		connection = SingleConnection.getConnection();
	}
}
<?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" 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>ProjetoFinal</display-name>
	
	<welcome-file-list>
		<welcome-file>Index.jsp</welcome-file>
		<filter>filter.Filter</filter>
	</welcome-file-list>
</web-app>

1 Resposta

L

Acredito que a declaração do filtro no web.xml está errada. Veja um exemplo: https://docs.oracle.com/cd/B14099_19/web.1012/b14017/filters.htm#i1000379

Criado 14 de junho de 2017
Ultima resposta 15 de jun. de 2017
Respostas 1
Participantes 2