Javaweb
-
Tomcat配置
- 之前学过,不赘述
-
Maven
- Maven核心思想:约定大于配置
- 修改镜像:阿里云
- 建立本地仓库
- idea配置maven
- 。。。
-
HelloServlet
-
构建一个普通的Maven项目,删掉src文件夹,在项目里面建立moudel
-
Maven环境优化:
- 修改web.xml为最新的
- 将maven的结构搭建完整
-
编写一个Servlet程序
- 编写一个普通类
- 实现Servlet接口,直接继承HttpServlet
public class HelloServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter writer = resp.getWriter(); writer.println("Hello,Servlet!"); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); } }
-
编写Servlet映射
<web-app> <display-name>Archetype Created Web Application</display-name> <!-- 注册Servlet--> <servlet> <servlet-name>hello</servlet-name> <servlet-class>com.zheng.servlet.HelloServlet</servlet-class> </servlet> <!-- Servlet的请求路径--> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping> </web-app>
- 配置Tomcat
- 启动测试,ok!
-