当前位置:网站首页>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 固件打包脚本软件

产业互联网中,「小」程序有「大」作为

Contrastive learning of Class-agnostic Activation Map for Weakly Supervised Object Localization and

Small program cloud development -- wechat official account article collection

MnasNet学习笔记

Image preloading in JS

在unity中使用jieba分词的方法

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

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

Share Creators萌芽人才培养计划来了!
随机推荐
【微信小程序开发】样式汇总
The operation efficiency of the park is improved, and the application platform management of applet container technology is accelerated
js中的图片预加载
Why are strings immutable in many programming languages? [repeated] - why are strings immutable in many programming languages? [duplicate]
Mnasnet learning notes
小程序自定义顶部导航栏,uni-app微信小程序自定义顶部导航栏
Optimal Transport系列1
Is it safe to open a stock account? Shanghai stock account opening procedures.
集群方法同步执行框架 Suona
Complete training and verification of a neural network based on pytorch
Ipmitool download address and possible problems during compilation and installation
Poj-3486-computers[dynamic planning]
Cluster method synchronous execution framework suona
Od modify DLL and exe pop-up contents [OllyDbg]
pycharm 软件deployment 灰色 无法点
Mouse over effect I
Mouse over effect 7
鼠标悬停效果二
大橙子疯博客搬家通知
SAP ALV汇总跟导出Excel 汇总数据不一致