当前位置:网站首页>Serenvlt first met
Serenvlt first met
2022-06-25 12:59:00 【Bo0o2】
One servelt What is it?
setvelt Is a dynamic page technology , It's a group. Tomcat For programmers API, Help programmers develop simply and efficiently
Two Servlet Operation principle
stay Servlet In our code, we didn't write main Method , So the corresponding doGet How is the code called ? How the response is returned to the browser ?
Tomcat The positioning of
Our own realization is in Tomcat Based on .
When the browser sends a request to the server , Tomcat As HTTP The server , You can receive this request .
HTTP As an application layer protocol , The underlying protocol stack is needed to support the work . As shown in the figure below :
3、 ... and HttpServlet
We write Servlet Code time , The first step is to create a class , Inherited from HttpServlet, And override some of them 
Code instance processing get request :
establish doget Method 
@WebServlet("/method")
public class method extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("GET response");
}
}

Enter... In the browser url Address , So the browser sends a message to the server get request 
Code instance processing post request :
First create a static html
<button onclick="sendPost()"> send out POST request </button>
<script> function sendPost() {
ajax({
method: 'POST', url: 'method', callback: function (body, status) {
console.log(body); } }) } </script>
Then create a post Method :
stay method Created in dopost Method :
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html; charset=utf-8");
resp.getWriter().write("POST Respond to ");
}
Click submit in the browser “post request ‘’
Four What to do if there is an error in accessing ?
Beginners Servlet, There will be many such problems . We don't just have to learn Servlet The basic way of writing code , We should also learn how to check for mistakes
Ideas .
Program debugging BUG Like a doctor .
An experienced programmer is compared to a novice programmer , The biggest advantage is not how well the code is written , But the debugging efficiency is
How high . The same problem may take a novice several days to solve , But an experienced programmer can do it in a few minutes .
be familiar with HTTP The protocol allows us to debug problems with half the effort .
4xx The status code of indicates that the path does not exist , Often need to check URL Whether it is right , And the... Set in the code Context Path as well as
Servlet Path Is it consistent .
5xx The status code of indicates that the server has an error , You often need to observe the content and content of the page prompt Tomcat Your own journal , Observe if
There is an error .
A connection failure often means Tomcat Not started correctly , Also need to observe Tomcat Whether there is an error prompt in your own log .
This situation of blank pages requires us to use the packet capture tool to analyze HTTP The specific interaction process of request response .
边栏推荐
- leetcode - 384. 打乱数组
- MySQL adds, modifies, and deletes table fields, field data types, and lengths (with various actual case statements)
- Concat(), join(), reverse(), sort() method in JS array
- Oracle trigger error report table or view does not exist
- leetcode - 384. Scramble array
- Negative sample image used in yolov5 training
- JS picture switching (simple and practical)
- 模块五(微博评论)
- JS function exercises
- Maximum number [abstract rules for abstract sorting]
猜你喜欢

二叉树之_哈夫曼树_哈弗曼编码
![[flask tutorial] flask development foundation and introduction](/img/c4/fb80fbe6b563e3b304d59623ef6465.jpg)
[flask tutorial] flask development foundation and introduction
![[转]以终为始,详细分析高考志愿该怎么填](/img/77/715454c8203d722e246ed70e1fe0d8.png)
[转]以终为始,详细分析高考志愿该怎么填
![[AI helps scientific research] fool drawing of loss curve](/img/38/5cb2a3d33a609dab3874215d5f7b5b.png)
[AI helps scientific research] fool drawing of loss curve

Online service emergency research methodology

mysql导入导出数据到excel表日期出现问题
![[Visio]平行四边形在Word中模糊问题解决](/img/04/8a1de2983d648e67f823b5d973c003.png)
[Visio]平行四边形在Word中模糊问题解决
Module 5 (microblog comments)

leetcode - 384. Scramble array

2021-10-21
随机推荐
JS array de duplication
浏览器的5种观察器
Parse JSON format data and save it to entity class
Used in time filter (EL table)
The drop-down box renders numbers instead of the corresponding text. How to deal with it
Render values to corresponding text
The amount is verified, and two zeros are spliced by integers during echo
CUDA error: unspecified launch failure
How to implement a high-performance load balancing architecture?
重磅直播|BizDevOps:数字化转型浪潮下的技术破局之路
Talk about 11 key techniques of high availability
Optimal solution for cold start
二叉树之_哈夫曼树_哈弗曼编码
JS SMS countdown implementation (simple code)
MySQL writes user-defined functions and stored procedure syntax (a detailed case is attached, and the problem has been solved: errors are reported when running user-defined functions, and errors are r
地理空间搜索 ->R树索引
Why are databases cloud native?
Match regular with fixed format beginning and fixed end
yolov5训练使用的负样本图片
Jupyter notebook theme font setting and automatic code completion