1Servlet

1sun提供的一种动态web资源开发技术.

2本质上就是一段java小程序.

3可以将Servlet加入到Servlet容器中运行.

*Servlet容器

-- 能够运行Servlet的环境就叫做Servlet容器. --- tomcat

*web容器

 -- 能够运行web应用的环境就叫做web容器 --- tomcat

2、如何开发一个servlet程序

1、写一个类实现sun公司定义的Servlet接口

2、将写好的类配置到tomcat中的web应用的web.xml,(配置对外访问路径)

            tomcat中内置了servlet的解析jar包,不用配servlet-api.jar


web.xml内容:    

<?xml version="1.0" encoding="UTF-8"?>

    <web-app version="2.5"

    xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

    " >http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <servlet>

        <servlet-name>FirstServlet</servlet-name>   Servlet的名字

        <servlet-class>com.itheima.FirstServlet</servlet-class>  Servlet类的的全路径名

    </servlet>

     

    <servlet-mapping>   对外访问路径配置 

        <servlet-name>FirstServlet</servlet-name>  Servlet的名字

        <url-pattern>/servlet/FirstServlet</url-pattern>   访问路径

    </servlet-mapping>

    </web-app>