当前位置:网站首页>Servlet fast foundation building
Servlet fast foundation building
2022-06-24 09:37:00 【Soup key TJ】
Catalog
Servlet Different mapping methods
Servlet Thread safety problem
- because Servlet It's using The singleton pattern , That is, there is only one instance object in the whole application
- So we need to analyze whether the class members in this unique instance object are thread safe
- A browser represents a thread , Multiple browsers represent multiple threads
- It is reasonable to say that what we expect is that each browser should view its own user name , But the result is a mess of data in the browser
- therefore , It can be said that Servlet It's not thread safe
- solve :
- Be careful when defining class members
- If it's shared , And will only be assigned at initialization time , If other times are obtained , Then there's no problem
- If it's not shared , Or it can be assigned a value every time it is used , Then we have to consider thread safety ; It can be defined as doGet or doPost Method or use the synchronization function
Servlet Different mapping methods
- The first one is
- The specific name of the way
- The resource path to be accessed must be exactly the same as the mapping configuration
- http://localhost:8080/demo2/cpc

- The second kind
- / start + The way of wildcards
- As long as it conforms to the directory structure , Don't worry about the ending
- http://localhost:8080/demo2/cpc/suibianxie

- The third kind of
- wildcard + Fixed format ending way
- As long as it conforms to the fixed ending format , Regardless of the path ahead
- http://localhost:8080/demo2/tjtjtj.cpc

- Be careful : Priority questions
- The more specific the priority, the higher , The more fuzzy it is, the lower the priority it has
- The first one is > The second kind > The third kind of
Servlet Multipath mapping
- You can give Servlet Configure multiple access maps , So different functions can be realized according to different request paths
- Scene analysis :
- If the access resource path is /vip
- The price of the goods hit 9 fold
- If the access resource path is /svip
- The price of the goods hit 5 fold
- If the accessed resource path is another
- There is no discount on the price of goods
- Code implementation
- getRequestURI() Method
- getRequestURI() Method returns a string , The content is the whole access url Of path Content , No query;
- example : Input url The address is http://localhost:8080/testproject/test
- getRequestURI() return /testproject/test, For one String
- To configure
- Use the second
- / start + The way of wildcards

- Code

- test
- http://localhost:8080/demo2/cpc/vip

- http://localhost:8080/demo2/cpc/svip

- http://localhost:8080/demo2/cpc

Servlet Create time
- Create... On first visit
- advantage : Reduce the waste of server memory ; Improve the efficiency of server startup
- disadvantages : If there are some initialization operations to be done when the application is loaded , Cannot complete
- Created when the server loads
- advantage : Create objects ahead of time , Improve the efficiency of first time execution ; You can complete some initialization operations when loading applications
- disadvantages : It takes up a lot of server memory , It affects the efficiency of server startup
- To be modified Servlet Create a time :
- Will be in <servlet> In the label , add to <load-on-startup> label
- Write an integer
- A positive integer represents the number created when the server loads , The smaller the value. , The higher the priority
- A negative integer or no write represents the first access to create
Default Servlet
- Default Servlet It's one provided by the server Servlet
- It's configured in Tomcat Of conf In the directory web.xml in
- Its mapping path is <url-pattern>/<url-pattern>
- When we send a request , First of all, it will be in our project web.xml Find mapping configuration in , If found, execute
- But when we can't find the corresponding Servlet When the path
- Just go to the default Servlet, By default Servlet Handle
- therefore , Everything is Servlet


边栏推荐
- Servlet快速筑基
- Cdga | how can we do well in data governance?
- 【自定义Endpoint 及实现原理】
- 可直接套用的Go编码规范
- 获取带参数的微信小程序二维码-以及修改二维码LOGO源码分享
- 如何让社交媒体成为跨境电商驱动力?这款独立站工具不能错过!
- Niuke network decimal integer to hexadecimal string
- MYCAT read / write separation and MySQL master-slave synchronization
- 零基础自学SQL课程 | HAVING子句
- 支持向量机(SVC,NuSVC,LinearSVC)
猜你喜欢

June 13-19, 2022 AI industry weekly (issue 102): career development

latex公式及表格识别
Depens:*** but it is not going to be installed

Epidemic situation, unemployment, 2022, we shouted to lie down!

Oracle数据文件头SCN不一致处理方法

Linux MySQL installation

零基础自学SQL课程 | 子查询

PRCT-1400 : 未能执行 getcrshome解决方法

R ellipse random point generation and drawing

支持向量机(SVC,NuSVC,LinearSVC)
随机推荐
【Eureka 源码分析】
Oracle数据库监听文件配置
PHP封装一个文件上传类(支持单文件多文件上传)
PRCT-1400 : 未能执行 getcrshome解决方法
Framework tool class obtained by chance for self use
读CVPR 2022目标检测论文得到的亿点点启发
PTA猴子选大王(约瑟夫环问题)
20、 Processor scheduling (RR time slice rotation, mlfq multi-level feedback queue, CFS fully fair scheduler, priority reversal; multiprocessor scheduling)
算法---矩阵中战斗力最弱的 K 行(Kotlin)
Epidemic situation, unemployment, 2022, we shouted to lie down!
Zero foundation self-study SQL course | syntax sequence and execution sequence of SQL statements
算法--找到和最大的长度为 K 的子序列(Kotlin)
CF566E-Restoring Map【bitset】
Applet wx show
Longest public prefix of leetcode
Webrtc series - network transmission 5: select the optimal connection switching
正则匹配手机号
leetcode--字符串
每周推荐短视频:计算的终极形态是“元宇宙”?
In depth analysis of Apache bookkeeper series: Part 3 - reading principle









