您的位置:365bet体育备用网址器 > 应用 > 需要将Servlet配置到该配置文件下

需要将Servlet配置到该配置文件下

2019-11-01 00:27

初识Servlet,Tencent录制初识设想化

1.创建DispatcherServlet 图片 1

 1 package myservlet;
 2 
 3 import java.io.IOException;
 4 import javax.servlet.ServletException;
 5 import javax.servlet.annotation.WebServlet;
 6 import javax.servlet.http.HttpServlet;
 7 import javax.servlet.http.HttpServletRequest;
 8 import javax.servlet.http.HttpServletResponse;
 9 
10 /**
11  * Servlet implementation class Dispatcher
12  */
13 @WebServlet("/Dispatcher")
14 public class Dispatcher extends HttpServlet {
15     private static final long serialVersionUID = 1L;
16        
17     /**
18      * @see HttpServlet#HttpServlet()
19      */
20     public Dispatcher() {
21         super();
22         // TODO Auto-generated constructor stub
23     }
24 
25     /**
26      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
27      */
28     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
29         // TODO Auto-generated method stub
30         response.getWriter().append("Served at: ").append(request.getContextPath());
31     }
32 
33     /**
34      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
35      */
36     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
37         // TODO Auto-generated method stub
38         doGet(request, response);
39     }
40 
41 }

View Code

2.将创建好的Servlet配置到web.xml

图片 2

1 <servlet>
2       <servlet-name>dispatcher</servlet-name>
3       <servlet-class>myservlet.DispatcherServlet</servlet-class>
4   </servlet>
5   
6   <servlet-mapping>
7       <servlet-name>dispatcher</servlet-name>
8       <url-pattern>/</url-pattern>
9   </servlet-mapping>

View Code

3.将项目配置到tomcat下就能够。

计算表明:

1.创造Servlet需继续汤姆cat下servlet-api.jar下的类库

2.web.xml是项目标计划文件,要求将Servlet配置到该配置文件下

3.Servlet是项目进口

(初读书人记录学习中的总括,希望各位大咖进行点评指正,多谢大家!)

 

1.创建DispatcherServlet 1 package myservlet; 2 3 import java.io.IOException; 4 import javax.servlet.ServletException; 5 import javax.s...

本文由365bet体育备用网址器发布于应用,转载请注明出处:需要将Servlet配置到该配置文件下

关键词:

  • 上一篇:没有了
  • 下一篇:没有了