---
# System prepended metadata

title: JSP 亂碼
tags: [JSP]

---

---
GA: UA-81246538-4
---
# JSP 亂碼
:::warning
後端建置 category 的功能時，複製 user.jsp 改成 category.jsp 時發現換頁時，兩個頁面的字型規格不同且出現中文亂碼
:::
:::success

嘗試網路中消除亂碼的方式(設定UTF-8編碼)沒有效果，仔細檢查兩者差異時發現了不同，刪除後 JSP 顯示正常。
:::

:::info
* ListUserServlet.java 中
```
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    UserServices userServices = new UserServices(entityManager, request, response);
    userServices.listUser();
}
```
![](https://i.imgur.com/5aW7pPl.png)

* ListCategoryServlet.java 中

```
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.getWriter().println("List Category");
    CategoryServices categoryServices = new CategoryServices(entityManager ,request, response);
    categoryServices.listCategory();
}
```
![](https://i.imgur.com/KiJ35Sv.png)

* 在 ListCategoryServlet.java 中刪除測試的句子

```
response.getWriter().println("List Category");
```
![](https://i.imgur.com/i2OhIdF.png)

:::
###### tags: `JSP`
