当前位置:网站首页>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 ;
边栏推荐
猜你喜欢

servlet【初识】

Restcloud ETL practice to realize incremental data synchronization without identification bit

Image preloading in JS

Zero foundation self-study SQL course | window function

【小程序项目开发--京东商城】uni-app之自定义搜索组件(上)

Sampling Area Lights

Xception learning notes

Pulsar Geo Replication/灾备/地域复制

Share Creators萌芽人才培養計劃來了!

Lenovo x86 server restart management controller (xclarity controller) or TSM method
随机推荐
视觉特效,图片转成漫画功能
SAP ALV summary is inconsistent with exported excel summary data
DenseNet网络论文学习笔记
Find the length of the common part of two line segments
如果我在北京,到哪里开户比较好?另外,手机开户安全么?
Add / delete / modify query summary insert/create/put/add/save/post, delete/drop/remove, update/modify/change, select/get/list/find
Contrastive learning of Class-agnostic Activation Map for Weakly Supervised Object Localization and
Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
C language a little bit (may increase in the future)
【PR #5 A】双向奔赴(状压DP)
In the industrial Internet, "small" programs have "big" effects
Dell服务器重启iDRAC方法
Codeforces Round #416 (Div. 2) C. Vladik and Memorable Trip
Mouse over effect II
Restcloud ETl数据通过时间戳实现增量数据同步
Sampling Area Lights
How to buy Hong Kong shares in China? What platform is safer?
鼠标悬停效果七
【小程序项目开发 -- 京东商城】uni-app 商品分类页面(上)
Poj-3486-computers[dynamic planning]