当前位置:网站首页>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 ;
边栏推荐
- Mouse over effect 8
- 联想X86服务器重启管理控制器(XClarity Controller)或TSM的方法
- Here comes the share creators budding talent training program!
- 鼠标悬停效果四
- Is it safe to open a stock account? Shanghai stock account opening procedures.
- 如果我在北京,到哪里开户比较好?另外,手机开户安全么?
- robots. Txt restrict search engine inclusion
- Introduction to kubernetes resource objects and common commands (II)
- Restcloud ETL data realizes incremental data synchronization through timestamp
- Optimal transport Series 1
猜你喜欢

MnasNet学习笔记

Sampling Area Lights

Proxy support and SNI routing of pulsar

Small program cloud development -- wechat official account article collection

Share Creators萌芽人才培养计划来了!

Pulsar Geo Replication/灾备/地域复制

Comment réaliser la liaison entre la serrure intelligente et la lampe, la scène du moteur de rideau intelligent dans le timing intelligent?

Pulsar geo replication/ disaster recovery / regional replication
![Od modify DLL and exe pop-up contents [OllyDbg]](/img/ff/7249e6e6644376ae048b23bf63b046.jpg)
Od modify DLL and exe pop-up contents [OllyDbg]

AI edge computing platform - beaglebone AI 64 introduction
随机推荐
In the industrial Internet, "small" programs have "big" effects
SAP ALV汇总跟导出Excel 汇总数据不一致
MnasNet学习笔记
Thread Detach
单片机 MCU 固件打包脚本软件
How to open a stock account? Also, is it safe to open an account online?
Share Creators萌芽人才培养计划来了!
Complete training and verification of a neural network based on pytorch
Restcloud ETL实践之数据行列转换
Find the length of the common part of two line segments
ssh配置免密登录时报错:/usr/bin/ssh-copy-id: ERROR: No identities found 解决方法
[PR # 5 A] two way running (state pressure DP)
RestCloud ETL WebService数据同步到本地
Evaluation of the entry-level models of 5 mainstream smart speakers: apple, Xiaomi, Huawei, tmall, Xiaodu, who is better?
AI 边缘计算平台 - BeagleBone AI 64 简介
import tensorflow. contrib. Slim as slim error
Pulsar的Proxy支持和SNI路由
【机器学习】向量化计算 -- 机器学习路上必经路
Applet custom top navigation bar, uni app wechat applet custom top navigation bar
Mouse over effect I