[Java] Create a filter

Create a filter for duplicate content to make the code cleaner! !! !!

EncodingFilter.java


package tool;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;

@WebFilter(urlPatterns = { "/*" })
public class EncodingFilter implements Filter {
	public void doFilter(
		ServletRequest request,
		ServletResponse response,
		FilterChain chain
	) throws IOException, ServletException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");

		System.out.println("Before filtering");

		chain.doFilter(request, response);

		System.out.println("After filtering");

	}

	public void init(FilterConfig filterconfig) {}

	public void destory() {
	}
}

Recommended Posts

[Java] Create a filter
Create a java method [Memo] [java11]
[Java] Create a temporary file
Create a Java project using Eclipse
[Java] How to create a folder
[Java] Servlet filter
[Java] Create and apply a slide master
Let's create a Java development environment (updating)
Create a TODO app in Java 7 Create Header
[Java] Filter stack traces
Create a CSR with extended information in Java
Create a simple bulletin board with Java + MySQL
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Let's create a timed process with Java Timer! !!
Create a Lambda Container Image based on Java 15
[Java] Create something like a product search API
Try to create a bulletin board in Java
java build a triangle
[Java] Create a collection with only one element
Let's create a super-simple web framework in Java
[Java] Let's create a mod for Minecraft 1.14.4 [Introduction]
Create Scala Seq from Java, make Scala Seq a Java List
[Java] Let's create a mod for Minecraft 1.16.1 [Introduction]
Create JSON in Java
[Java] Let's create a mod for Minecraft 1.14.4 [99. Mod output]
[Java] Let's create a mod for Minecraft 1.14.4 [0. Basic file]
Create a portfolio app using Java and Spring Boot
Create a Java development environment using jenv on Mac
[Java] Let's create a mod for Minecraft 1.14.4 [4. Add tools]
[Java] Let's create a mod for Minecraft 1.14.4 [5. Add armor]
[Java] Let's create a mod for Minecraft 1.14.4 [Extra edition]
[Java] Let's create a mod for Minecraft 1.14.4 [7. Add progress]
[Java] Let's create a mod for Minecraft 1.14.4 [6. Add recipe]
[Beginner] Create a competitive game with basic Java knowledge
[Java] Let's create a mod for Minecraft 1.16.1 [Add item]
[Java] Let's create a mod for Minecraft 1.16.1 [Basic file]
Java / Twitter clone / task management system (1) Create a database
I tried to create a Clova skill in Java
[Java] Let's create a mod for Minecraft 1.14.4 [1. Add items]
How to create a data URI (base64) in Java
[Note] Create a java environment from scratch with docker
Create a Java, JavaScript team development environment (problem raising)
[Java] Let's create a mod for Minecraft 1.14.4 [2. Add block]
Create a JAVA WEB application and try OMC APM
[Java] Let's create a mod for Minecraft 1.16.1 [Add block]
Create hyperlinks in Java PowerPoint
Create a VS Code Plugin.
Find a subset in Java
Create a playground with Xcode 12
Create Azure Functions in Java
What is a Java collection?
[Java] Make it a constant
Create your own Java annotations
Create a fortune using Ruby
[Java] Draw a simple pattern
[Swift] Apply a gradation filter
Try implementing a WebFlux filter
Java creates a Word document
Make a rhombus using Java
How to create a method
Create a name input function