### (5)Eclipse新建Web项目 新建工作目录文件夹 ``` D:\Workspace\EclipseWorkspace ``` 新建动态web项目,否则没有WebContent、lib等目录 给项目配置Tomcat,之前我们是将Tomcat配置到Eclipse,现在是将Tomcat配置到项目中 新建一个IndexServlet控制器 ```java package cn.tellsea.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * 首页 * * @author Tellsea * */ @WebServlet("") @SuppressWarnings("serial") public class IndexServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.getRequestDispatcher("/index.jsp").forward(req, resp); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { } } ``` 在WebContent下创建一个index.jsp文件 ```html <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> 哈哈 </body> </html> ``` 启动项目,访问测试页面,发现中文乱码,然后我们继续把页面头部修改为以下内容,再次测试,发现中文乱码问题已经解决 ```html <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> ``` 新建项目测试完成