一、搭建项目工程
百度云下载:http://pan.baidu.com/s/1c18VOwo
下载完之后解压,如下
idea启动如果出现乱码,在这里可以配置为相应编码
在bin目录下启动和停止tomcat
启动之后,访问http://localhost:8080/ 如果加载出Apache Tomcat的页面,即说明启动成功。
三、Idea整合tomcat搭建servlet Demo 3.1 业务类public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1.获取前端参数
String method = req.getParameter("method");
if (method.equals("add")) {
req.getSession().setAttribute("msg", "aaa");
}
if (method.equals("delete")) {
req.getSession().setAttribute("msg", "执行了delete方法");
}
//2.调用业务层
//3.视图转发或者重定向
req.getRequestDispatcher("/WEB-INF/jsp/test.jsp").forward(req, resp);
}
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
3.2 web.xml
hello
com.best.servlet.HelloServlet
hello
/hello
15
index.jsp
3.3 jsp
3.3.1 form.jsp
Title
3.3.2 test.jsp
Title
${msg}
3.4 集成Tomcat
启动程序
访问: http://localhost:8080/hello?method=delete
源码链接,视频教程,参考