---
# System prepended metadata

title: Filter
tags: [Spring  MVC]

---

---
tags: Spring  MVC
---
# Filter
因輸入文字為中文，系統認不得會變成亂碼，可經由Filter 通知 Spring ，輸入資料的編碼。
![](https://i.imgur.com/aIYKiLS.png)


作法
在 WebAppInitializer.java覆寫getServletFilters()方法

```
@Override
	protected Filter[] getServletFilters() {
		CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
		characterEncodingFilter.setEncoding("UTF-8");
		return new Filter[] {characterEncodingFilter};
	}
```