• 从零开始写JavaWeb框架(第二章节)


    这一章太多了。。。好累,不想写那么细了,就做一点总结吧。

    package org.smart4j.chapter2.controller;
    
    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;
    
    /**
     * 创建客户
     */
    @WebServlet("/customer_create")
    public class CustomerCreateServlet extends HttpServlet {
    
        /**
         * 进入 创建客户 界面
         */
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            // TODO
        }
    
        /**
         * 处理 创建客户 请求
         */
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            // TODO
        }
    }
    @WebServlet("/customer_create")这个就是表明请求路径是/customer_create,该servlet只有一个请求路径,但是可以两种不同的请求类型。(注意GET方法是默认的HTTP请求方法)
    在Servlet中,请求类型有GET,POST,PUT,DELETE,分别对应doGet,doPost,doPut,doDelete方法。

    推荐将JSP放到WEB-INF内部而不是外部,因为内部无法通过浏览器地址栏直接请求放在内部的JSP,必须通过Servlet程序进行转发或者重定向。

    我们为了确保线程中只有一个Connection,可以使用ThreadLocal来存放本地线程变量,可以将ThreadLocal理解为一个隔离线程的容器。
  • 相关阅读:
    C++异常:exception
    C++关键字:explicit
    C++关键字:重学记录
    Unity jointmoto
    hashtable和hashmap
    Spring MVC 笔记 概述
    SQL上门2
    面试:A
    Java 初学者
    SQL上门
  • 原文地址:https://www.cnblogs.com/XJJD/p/7577390.html
Copyright © 2020-2023  润新知