当前位置:网站首页>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
边栏推荐
- Electron入门教程3 ——进程通信
- Mysql database - connection query
- nc基础用法3
- STM32 Basics
- Physical meaning of FFT: 1024 point FFT is 1024 real numbers. The actual input to FFT is 1024 complex numbers (imaginary part is 0), and the output is also 1024 complex numbers. The effective data is
- Kibana reports an error server is not ready yet. Possible causes
- @Mapperscan and @ mapper
- STM32基础知识
- PCL点云处理之直线与平面的交点计算(五十三)
- PCL点云处理之计算两平面交线(五十一)
猜你喜欢
C6748 software simulation and hardware test - with detailed FFT hardware measurement time
Unity general steps for creating a hyper realistic 3D scene
selenium. common. exceptions. WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
Esp8266 - beginner level Chapter 1
SIGIR'22「微软」CTR估计:利用上下文信息促进特征表征学习
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(五)
【数值预测案例】(3) LSTM 时间序列电量预测,附Tensorflow完整代码
LeetCode动态规划训练营(1~5天)
Compact CUDA tutorial - CUDA driver API
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (VII)
随机推荐
Leetcode dynamic planning training camp (1-5 days)
Openharmony open source developer growth plan, looking for new open source forces that change the world!
NC basic usage 3
Cadence Orcad Capture 批量更改元件封装功能介绍图文教程及视频演示
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (V)
R语言ggplot2可视化分面图(facet_wrap)、使用lineheight参数自定义设置分面图标签栏(灰色标签栏)的高度
Comment créer un pass BEP - 20 sur la chaîne BNB
R language uses timeroc package to calculate the multi time AUC value of survival data under competitive risk, uses Cox model and adds covariates, and R language uses the plotauccurve function of time
Cadence Orcad Capture CIS更换元器件之Link Database 功能介绍图文教程及视频演示
R语言使用caret包的preProcess函数进行数据预处理:对所有的数据列进行BoxCox变换处理(将非正态分布数据列转换为正态分布数据、不可以处理负数)、设置method参数为BoxCox
Redis installation (centos7 command line installation)
如何在BNB鏈上創建BEP-20通證
MySQL advanced lock - overview of MySQL locks and classification of MySQL locks: global lock (data backup), table level lock (table shared read lock, table exclusive write lock, metadata lock and inte
数据库查询 - 选课系统
Lpc1768 optimization comparison of delay time and different levels
渤海期货这家公司怎么样。期货开户办理安全?
Kubernetes getting started to proficient - install openelb on kubernetes
Design of library management database system
Redis distributed lock
本地调用feign接口报404