<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>day34</display-name>
<!-- 进行servlet的注册 -->
<!-- servlet-class用于servlet的完整的类名, -->
<!-- servlet-name用于servlet的注册名, -->
<servlet>
<servlet-name>DemoServlet_1</servlet-name>
<servlet-class>donghongyujava.servlet.DemoServlet_1</servlet-class>
</servlet>
<servlet>
<servlet-name>DemoServlet_2</servlet-name>
<servlet-class>donghongyujava.servlet.DemoServlet_2</servlet-class>
</servlet>
<servlet>
<servlet-name>DemoServlet_3</servlet-name>
<servlet-class>donghongyujava.servlet.DemoServlet_3</servlet-class>
</servlet>
<!-- 创建虚拟的 映射地址指向注册过的servlet -->
<!-- 同一个servlet的服务程序可以由多个虚拟映射指向 -->
<!-- 虚拟映射的作用,提供给外界访问web服务器中资源的URL地址 -->
<!-- servlet-name指向servlet的注册名称 -->
<!-- url-pattern 设置servlet对外访问的路径 -->
<servlet-mapping>
<servlet-name>DemoServlet_1</servlet-name>
<url-pattern>/servlet/DemoServlet_1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DemoServlet_1</servlet-name>
<url-pattern>/DemoServlet_1.html</url-pattern>
</servlet-mapping>
<!-- * 代表的是通配符:有两个种固定的格式: 一种:" *.扩展名 "; 另一种:" /action /* " -->
<servlet-mapping>
<servlet-name>DemoServlet_2</servlet-name>
<url-pattern>/src/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DemoServlet_3</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
package donghongyujava.servlet;
import java.io.IOException;
public class DemoServlet_1 extends HttpServlet {
/**
* Constructor of the object.
*/
public DemoServlet_1() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" DemoServlet_1 ");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
package donghongyujava.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DemoServlet_2 extends HttpServlet {
/**
* Constructor of the object.
*/
public DemoServlet_2() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" DemoServlet_2 ");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
package donghongyujava.servlet;
import java.io.IOException;
public class DemoServlet_3 extends HttpServlet {
/**
* Constructor of the object.
*/
public DemoServlet_3() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" DemoServlet_3");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
分享到:
相关推荐
Servlet API 中文参考 chm,涉及Servet资料资料、API介绍,讲述Servlets概论、生命周期、解析和载入、初始化、 Servlet处理请求、多线程和映射、Servlet的卸载、Servlet映射技术、通... Servlet API 中文参考 chm,...
说白话,就是给你建的Servlet起一个别名,把路径改成浏览器访问的方式,只有把Servlet映射成虚拟路径,客户端才能对其进行访问 新建一个动态web项目后,然后新建好servlet之后,打开web.xml 打开你的web.xml,我们...
Servlet_ServletAnnotations Servlet API 3.0引入了一个名为javax.servlet.... 注释可以替换Web部署描述符文件(web.xml)中的等效XML配置,例如servlet声明和servlet映射。 Servlet容器将在部署时处理带注释的类。
主要介绍了Servlet虚拟路径映射配置详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
1,声明servlet及映射 2,加上@ServletComponentScan 才会扫描加了这个注解 运行结果 方法2:使用springboot提供的注册 Servlet 配置类 运行结果 方法3:动态注册: Servlet类 配置类 springboot内部绑定了嵌入式...
Servlet映射技术\r 作为一个Servlet引擎的开发者,你必须对于如何映射客户端的请求到Servlet有大量的适应性。这份说明文档不规定映射如何发生。但是,你必须能够自由地运用下面的所有技术: 映射一个Servlet到一个...
Servlet技术是Java Web开发中常用的一种技术,用于响应用户请求并生成动态内容。...您可以将编译后的Servlet类文件(.class文件)部署到Servlet容器中,并在Web应用程序的web.xml文件中配置Servlet映射。
JavaWeb开发技术-实现Servlet虚拟路径的映射.pptx
在上一篇中我们初识了Servlet,相信大家对Servlet也都有了些了解,知道了如何创建一个Servlet,并且为其添加虚拟映射,最终发布项目,并在浏览器上请求对应的Servlet。 我们知道,只有给Servlet配置好虚拟路径...
如何注册和运行Servlet,Servlet映射的细节和最具体匹配原则,用一个实例演示了注册和访问Servlet程序的整个过程。
當user從client端向web服務器發送一個http請求時,服務器就會分配一個線程來服務這個http請求,web容器會檢查是否有與此http url映射對應的servlet,如果沒有servlet容器會根據web.xml配置文件加載對應的servlet,并...
基于servlet3.0手写springmvc,实现了IOC和处理器映射器以及处理器映射器功能。
2.2.1 关于 Single Thread Model..............................................................................................................16 2.3 Servlet 生命周期 .......................................
Servlet API 中文参考 chm,涉及Servet资料资料、API介绍,讲述Servlets概论、生命周期、解析和载入、初始化、 Servlet处理请求、多线程和映射、Servlet的卸载、Servlet映射技术、通过类名调用Servlet、HTTP会话、...
用于把一个servlet 别名映射成一个url访问规则,匹配过程中,精确匹配,目录匹配,后缀匹配
tomcat在配置web.xml的时候,servlet是一个比较重要的问题,在这里讨论一下servlet中的几个痛点 servlet url-pattern的匹配问题 url-pattern中 / 和 /* 的区别 url-pattern的优先级问题 根路径 / 的匹配问题 1 ...
基于Servlet的搜索引擎,张文,,基于Servlet技术和数据结构中的哈希映射,以构建索引表的方式对网页关键字进行组织。根据客户端提供的关键字对索引表分析,得到搜��
1.创建:当用户第一次请求servlet映射的路径时,服务器会加载servlet并实例化,后续用户请求同一个servlet时,服务器都会用同一个servlet实例来响应用户的请求。如果希望服务器启动后立即实例化servlet,需要在配置...
还可能包含配置文件如web.xml,用于配置Servlet映射等。至于数据库部分,则包括了MySQL的数据库文件,其中存储了博客系统的数据结构、初始数据以及存储过程等。此资料包是一套学习和实践Web开发的好材料,尤其适合...
主要介绍了JavaWeb Servlet中url-pattern的使用的相关资料,希望通过本文能帮助到大家,让大家学习理解这部分内容,需要的朋友可以参考下