新建项目
创建classes目录和lib以及指定两个目录
指定web应用
配置tomcat
新建servlet
第一步进行拦截,拦截之后,根据name寻找servlet文件
@WebServlet("/servlet/FirstServlet")
//"/servlet/FirstServlet":相当于url-pattern
public class FirstServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.getWriter().write("this is first servlet");
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
}
访问Servlet
*配置Servlet模板
乱码
- 进入到tomcat的conf目录下找到 logging.properties
- 大概在47行出,将黄色部分的UTF-8编码改为GBK编码即可