단순 코드 기록/JavaSevlet

JavaSevlet_Filter

일일일코_장민기 2024. 2. 11. 14:31
728x90
Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">

<filter>

<filter-name>encoding</filter-name>

<filter-class>com.filter.EncodingFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>encoding</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

</web-app>

 

EncodingFilter

package com.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class EncodingFilter implements Filter{

@Override
public void destroy() {
// TODO Auto-generated method stub

}

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
chain.doFilter(request, response);

}

@Override
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}

}

 

 

'단순 코드 기록 > JavaSevlet' 카테고리의 다른 글

서블릿_Basic  (0) 2024.03.06
JavaSevlet_Request / Redirect  (0) 2024.02.11
JavaSevlet_Scope  (0) 2024.02.11
JavaSevlet_Param  (0) 2024.02.11
JavaSevlet_MVC  (0) 2024.02.11