当前位置:网站首页>Servlet learning notes
Servlet learning notes
2022-04-23 20:13:00 【Jiugui wine!!!】
Catalog
Two 、 Development Servlet The of the program only needs two steps
( One ) To write servlet Class implementation Servlet Interface and its hierarchical relationship
( Two ) Write servlet Class deployment to web The server
3、 ... and 、Servlet Operating mechanism 、 working principle
One 、Servlet What is it? ?
Servlet It is a kind of operation in Web Server side Java Applications , Can produce dynamic web page , It's a kind of API Interface . meanwhile Servlet Belong to JSP The bottom of the ,Servlet It's a Java class , function JSP when , The bottom layer of the server will JSP It will compile into a Java class , This class is Servlet.
Two 、 Development Servlet The of the program only needs two steps
To achieve Servlet Interface Java The program is called Servlet
The user uses the browser to request Servlet Of url How to write ???
localhost:8080/ Project name /<url-pattern>
( One ) To write servlet Class implementation Servlet Interface and its hierarchical relationship
1、 self-written servlet Class to inherit HttpServlet class
2、 rewrite HttpServlet Of doGet() perhaps doPost() Method
( Two ) Write servlet Class deployment to web The server
1、 To configure web.xml file : First, register servlet、 The second is the setting servlet The request path for
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <!-- register servlet --> <servlet> <servlet-name>hello</servlet-name> <servlet-class>com.dai.servlet.HelloServlet</servlet-class> </servlet> <!-- Set up servlet The request path for --> <servlet-mapping> <servlet-name>hello</servlet-name> <url-pattern>/url</url-pattern> </servlet-mapping> </web-app> <!-- servlet working principle ==> url-pattern: It is equivalent to specifying a request path , When the user requests to enter Tomcat Server's webapps The project name inside servlet1 after ( Here is http://localhost:8080/servlet1) Next, add... After the path /url(http://localhost:8080/servlet1/url), You can visit the servlet 了 , Will be in web.xml Inside <servlet-mapping> seek <url-pattern> yes /url Of When you find it, you know what to do /url Of servlet The name is called hello, Then go to <servlet> Who does it match servlet Name is hello, After matching successfully , It's time to do it servlet Inside <servlet-class> Class Corresponding doGet doPost Method -->
<servlet></servlet> Used to declare a servlet The data of , There are mainly the following sub elements :
- <servlet-name></servlet-name> Appoint servlet The name of
- <servlet-class></servlet-class> Appoint servlet Class name of
- <servlet-mapping></servlet-mapping> Used to define servlet The corresponding URL mapping , It contains two sub elements
- <servlet-name></servlet-name> Appoint servlet The name of
- <url-pattern></url-pattern> Appoint servlet The corresponding URL
3、 ... and 、Servlet Operating mechanism 、 working principle
Operating mechanism :
servlet In a life cycle , Only one... Will be instantiated servlet object , In the 1 Create... On access , The first 2 Only run... On this visit doGet and doPost Method .
servlet It adopts multithreading mechanism , Every request , The system will allocate a thread to run doGet function
working principle :
When Web After the server receives the request from the browser , Do the following work :
版权声明
本文为[Jiugui wine!!!]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210556007147.html
边栏推荐
- SRS deployment
- R language ggplot2 visual facet_wrap, and use the lineheight parameter to customize the height of the facet icon tab (gray label bar)
- Openharmony open source developer growth plan, looking for new open source forces that change the world!
- php参考手册String(7.2千字)
- Leetcode XOR operation
- Change the material of unity model as a whole
- Design of warehouse management database system
- Shanda Wangan shooting range experimental platform project - personal record (V)
- Redis cache penetration, cache breakdown, cache avalanche
- PCL点云处理之计算两平面交线(五十一)
猜你喜欢
@Mapperscan and @ mapper
SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
Kubernetes introduction to mastery - ktconnect (full name: kubernetes toolkit connect) is a small tool based on kubernetes environment to improve the efficiency of local test joint debugging.
Shanda Wangan shooting range experimental platform project - personal record (V)
DTMF双音多频信号仿真演示系统
Computing the intersection of two planes in PCL point cloud processing (51)
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (V)
Building googlenet neural network based on pytorch for flower recognition
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
C6748 software simulation and hardware test - with detailed FFT hardware measurement time
随机推荐
[target tracking] pedestrian attitude recognition based on frame difference method combined with Kalman filter, with matlab code
Electron入门教程4 —— 切换应用的主题
AQS learning
Redis的安装(CentOS7命令行安装)
还在用 ListView?使用 AnimatedList 让列表元素动起来
LeetCode异或运算
Database query - course selection system
Azkaban recompile, solve: could not connect to SMTP host: SMTP 163.com, port: 465 [January 10, 2022]
MySQL数据库 - 单表查询(三)
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(七)
Still using listview? Use animatedlist to make list elements move
STM32 Basics
MySQL数据库 - 单表查询(二)
MFC obtains local IP (used more in network communication)
LeetCode动态规划训练营(1~5天)
【数值预测案例】(3) LSTM 时间序列电量预测,附Tensorflow完整代码
R语言使用timeROC包计算无竞争风险情况下的生存资料多时间AUC值、使用confint函数计算无竞争风险情况下的生存资料多时间AUC指标的置信区间值
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (V)
Software College of Shandong University Project Training - Innovation Training - network security shooting range experimental platform (8)
How to do product innovation—— Exploration of product innovation methodology I