当前位置:网站首页>Sending and receiving of request parameters
Sending and receiving of request parameters
2022-07-03 08:45:00 【The corner of fufu】
Catalog
One 、 Request parameters
- The request parameter means that the browser sends a request to Tomcat Data submitted
- Request parameters are usually data entered by the user , stay Servlet To deal with
- Parameter name 1= value 1& Parameter name 2= value 2
Two 、 Send and receive request parameters
html page
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> Information registration form </title>
</head>
<body>
<h1> Information registration form </h1>
<form action="/FirstServlet/sample">
<table>
<tr>
<td> full name :</td>
<td><input name="name"/></td>
</tr>
<tr>
<td> Telephone :</td>
<td><input name="mobile"/></td>
</tr>
<tr>
<td> Gender :</td>
<td>
<select name="sex">
<option value="male"> male </option>
<option value="female"> Woman </option>
</select>
</td>
</tr>
<tr>
<td> hobby :</td>
<td>
<input type="checkbox" name="hobby" value="Swimming"/> swimming
<input type="checkbox" name="hobby" value="Speech"/> speech
<input type="checkbox" name="hobby" value="Reading"/> read
<input type="checkbox" name="hobby" value="Program"/> Programming
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value=" Submit ">
</td>
</tr>
</table>
</form>
</body>
</html>
java page
package com.imooc.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SampleServlet extends HttpServlet{
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
String name = request.getParameter("name");
String mobile = request.getParameter("mobile");
String sex = request.getParameter("sex");
String[] hobby1 = request.getParameterValues("hobby");
PrintWriter out = response.getWriter();
out.println("<h1>information</h1>");
out.println("<h3>name:"+ name + "</h3>");
out.println("<h3>mobile:"+ mobile + "</h3>");
out.println("<h3>sex:"+ sex + "</h3>");
for(int i=0;i<hobby1.length;i++) {
out.println("<h3>hobby:"+ hobby1[i] + "</h3>");
}
out.println("<a href='http://www.baidu.com'>baidu</a>");
}
}
Submission of request parameters 
Output 
3、 ... and 、Get and Post request
- Get The way is to pass the data in URL Additional data explicitly sends data to the server ( It is often used in query functions that do not contain sensitive information )
- Post The method will store the data in “ Request body ” Send data to the server implicitly ( For functions with high security or servers “ Write ” operation )
1、 Network data differences
(1)Get request 

(2)Post request 

2、 The treatment is different , The effect is different
(1)Get request
// Handle get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
String name = request.getParameter("name");
response.getWriter().println("<h1 style='color:green'>" + name + "</h1>");
}
<form action=“/FirstServlet/request_method” method=“get”>
(2)Post request
// Handle post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String name = request.getParameter("name");
response.getWriter().println("<h1 style='color:red'>" + name + "</h1>");
}
<form action=“/FirstServlet/request_method” method=“post”>
边栏推荐
- Constraintlayout's constraintset dynamically modifies constraints
- Vscode, idea, VIM development tool shortcut keys
- Analysis of Alibaba canal principle
- Servlet的生命周期
- [MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle
- Data analysis exercises
- Explain sizeof, strlen, pointer, array and other combination questions in detail
- P1596 [USACO10OCT]Lake Counting S
- UE4 source code reading_ Mobile synchronization
- Unity editor expansion - the design idea of imgui
猜你喜欢

Dom4j遍历和更新XML
![[rust notes] 02 ownership](/img/f7/74f8ea3bd697957f9ebfa3e1513fda.png)
[rust notes] 02 ownership

Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network

Concurrent programming (VI) ABA problems and solutions under CAS

Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)

22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令

UE4 source code reading_ Bone model and animation system_ Animation process

Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)

Ue5 opencv plug-in use

Installation of PHP FPM software +openresty cache construction
随机推荐
[redis] redis persistent RDB vs AOF (source code)
Clion toolchains are not configured configure disable profile problem solving
[concurrent programming] concurrent security
[concurrent programming] atomic operation CAS
【Rust 笔记】11-实用特型
Mxone Pro adaptive 2.0 film and television template watermelon video theme apple cmsv10 template
[concurrent programming] collaboration between threads
Dealing with duplicate data in Excel with xlwings
Osgearth north arrow display
[concurrent programming] working mechanism and type of thread pool
Unity editor expansion - scrolling list
MySQL index types B-tree and hash
Advanced OSG collision detection
[cloud native] introduction and use of feign of microservices
Monotonic stack -503 Next bigger Element II
[concurrent programming] explicit lock and AQS
Chocolate installation
Unity multi open script
Image processing 8-cnn image classification
了解小程序的笔记 2022/7/3

