当前位置:网站首页>Servlet [first introduction]
Servlet [first introduction]
2022-07-01 02:48:00 【Fate friend I】
List of articles
servlet
1.1 serlvt brief introduction
- servlet Namely sun Company development trends web A technology of
- Sun In these Apl Provides an interface called :Servlet, If you want to develop a Serlvet Program , Just two small steps :
- Write a class , Realization Serlvet Interface
- Put the developed Java Class deployment to web Server .
- To achieve Serlvet Interface java The program is called :Serlvet
1.2 HelloSerlvet
- Serlvet Interface sun The company has two default implementation classes :HttpServlet
Build a common Maven project 【 Don't use templates 】, Delete the inside src Catalog , It will be established in this project in the future model; This is an empty project Maven Main works
About Maven Understanding of father son project :
There will be :
<modules>
<module>servlet-01</module>
</modules>
There will be :
<parent>
<artifactId>javaweb-02-maven</artifactId>
<groupId>com.yang</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
In the parent project Java Subprojects can directly use
son extends father
- Maven Environmental optimization
- modify web.xml For the latest
- take maven The structure of the building is complete
- Write a Servlet Program
- Write a common class
- Realization Serlvet Interface , Direct inheritance HttpServlet
public class HelloServlet extends HttpServlet {
// because get perhaps post It's just that the request is implemented in a different way , Can call each other , The business logic is the same
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter writer = resp.getWriter();
writer.println("hello,servlet");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
}
}
- To write Servlet Mapping
Why do I need to map : The browser needs to connect web The server , What we're writing is IAVA Program , But access it through a browser , So we need to web Registration in the service we wrote Servlet, You also need to give him a path that the browser can access
<!-- register Servlet-->
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.yang.servlet.HelloServlet</servlet-class>
</servlet>
<!--Servlet The request path for -->
<servlet>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet>
- To configure Tomcat
Be careful : Just configure the project publishing path - Start the test
1.3 Servlet Execution principle
1.4 Mapping problem
- One Servlet You can specify a mapping path
- One servlet Multiple mapping paths can be specified
- One Servlet You can specify a generic mapping path
- Request default path
- Specify some suffixes or prefixes and so on ……
- Priority questions
Fixed mapping path is specified with the highest priority , If you can't find it, you will go to the default processing request ;
边栏推荐
猜你喜欢
MCU firmware packaging Script Software
基于Pytorch完整的训练一个神经网络并进行验证
Xception学习笔记
The mobile edge browser cannot open the third-party application
Optimal Transport系列1
The operation efficiency of the park is improved, and the application platform management of applet container technology is accelerated
Introduction to kubernetes resource objects and common commands (II)
Gartner research: in China, the adoption of hybrid cloud has become the mainstream trend
Focusing on green and low carbon, data center cooling has entered a new era of "intelligent cooling"
Nacos configuration center tutorial
随机推荐
【微信小程序开发】样式汇总
鼠标悬停效果六
如果我在北京,到哪里开户比较好?另外,手机开户安全么?
Record a service deployment failure troubleshooting
A shooting training method based on the digital measurement of Joule energy and posture of sphygmomanometer air bag with standard air pressure
CentOS installs multiple versions of PHP and switches
js防抖和节流
Proxy support and SNI routing of pulsar
go: finding module for package
Restcloud ETL data realizes incremental data synchronization through timestamp
鼠标悬停效果九
鼠标悬停效果四
Pulsar 主题压缩
Focusing on green and low carbon, data center cooling has entered a new era of "intelligent cooling"
SAP ALV summary is inconsistent with exported excel summary data
Catch 222222
MnasNet学习笔记
鼠标悬停效果三
Applet custom top navigation bar, uni app wechat applet custom top navigation bar
Restcloud ETL WebService data synchronization to local