zoukankan      html  css  js  c++  java
  • 从零开始写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理解为一个隔离线程的容器。
  • 相关阅读:
    Mysql上手
    Markdown精简版个人语法
    Sublime Text3插件管理
    Eclipse的快捷键
    使用github page 页面建博客中遇到的几个小问题
    2015 圣诞 限免软件分享
    啦啦啦-根据关键字进行字符串拷贝
    使用 sprintf swprintf 函数进行 unicode 与 ANSI 编码的转换
    c++11: 用户定义字面量
    通过模板获取数组长度
  • 原文地址:https://www.cnblogs.com/XJJD/p/7577390.html
Copyright © 2011-2022 走看看