博客
关于我
Servlet 体系结构与 urlpartten 配置_hehe.employment.over.14.1
阅读量:387 次
发布时间:2019-03-05

本文共 1848 字,大约阅读时间需要 6 分钟。

文章目录

14.1 Servlet_体系结构

  • Servlet 接口 < —— GenericServlet 抽象类 < —— HttpServlet 抽象类

  • GenericServlet: 将Servlet接口中其他的方法做了默认空实现,只将service()方法作为抽象

    • 将来定义Servlet类时,可以继承GenericServlet,实现service()方法即可
  • HttpServlet: 对http协议的一种封装,简化操作。

    • 1.定义类继承HttpServlet
    • 2.复写doGet/doPost方法
  • 图示:

    在这里插入图片描述

  • 示例:

package com.xww.web.servlet;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;@WebServlet("/demo1")public class ServetHttpDemo extends HttpServlet {       @Override    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {           System.out.println("doget....");    }    @Override    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {           System.out.println("dopost...");    }}

14.2 Servlet_urlpartten配置

  • urlpartten: Servlet访问路径
    • 一个Servlet可以定义多个访问路径 : eg: @WebServlet({"/x","/xw","/xww"})
    • 路径定义规则:
      • /xxx: 路径匹配 。访问方式:http://localhost:8080/xww
      • /xxx/xxx: 多层路径,目录结构。 访问方式:http://localhost:8080/x/xww
      • *.do: 扩展名匹配。 访问方式:http://localhost:8080/xww.do
  • 示例:
package com.xww.web.servlet;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;/** * Servlet路径配置 *///@WebServlet({"/x","/xw","/xww"})//@WebServlet("/x/xw")//@WebServlet("/x/*")//@WebServlet("/*")@WebServlet("*.do")public class ServletUrlDemo extends HttpServlet {       @Override    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {           System.out.println("doget...");    }}

转载地址:http://skgwz.baihongyu.com/

你可能感兴趣的文章
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>
mysqlbinlog报错unknown variable ‘default-character-set=utf8mb4‘
查看>>
mysqldump 参数--lock-tables浅析
查看>>
mysqldump 导出中文乱码
查看>>
mysqldump 导出数据库中每张表的前n条
查看>>
mysqldump: Got error: 1044: Access denied for user ‘xx’@’xx’ to database ‘xx’ when using LOCK TABLES
查看>>
Mysqldump参数大全(参数来源于mysql5.5.19源码)
查看>>
mysqldump备份时忽略某些表
查看>>
mysqldump实现数据备份及灾难恢复
查看>>
mysqldump数据库备份无法进行操作只能查询 --single-transaction
查看>>
mysqldump的一些用法
查看>>
mysqli
查看>>
MySQLIntegrityConstraintViolationException异常处理
查看>>