当前位置:网站首页>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”>
边栏推荐
- Deep parsing JVM memory model
- UE4 source code reading_ Bone model and animation system_ Animation process
- Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)
- [set theory] order relation (total order relation | total order set | total order relation example | quasi order relation | quasi order relation theorem | bifurcation | quasi linear order relation | q
- matlab神經網絡所有傳遞函數(激活函數)公式詳解
- UE4 source code reading_ Mobile synchronization
- JS ternary operator - learning notes (with cases)
- UE4 source code reading_ Bone model and animation system_ Animation compression
- URL backup 1
- Explain sizeof, strlen, pointer, array and other combination questions in detail
猜你喜欢

Notes on understanding applets 2022/7/3
![[concurrent programming] consistency hash](/img/5e/3d0a52caa8ca489a6e6267274bbb39.jpg)
[concurrent programming] consistency hash

MySQL 8

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

了解小程序的笔记 2022/7/3

Kwai 20200412 recruitment

Unity Editor Extension - drag and drop

Unity editor expansion - scrolling list
![[updating] wechat applet learning notes_ three](/img/05/958b8d62d3a42b38ca1a2d8631a7f8.png)
[updating] wechat applet learning notes_ three

Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
随机推荐
Ue5 opencv plug-in use
22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
Unity interactive water ripple post-treatment
Huawei interview summary during the epidemic
[concurrent programming] thread foundation and sharing between threads
redis集群系列四
Detailed explanation of all transfer function (activation function) formulas of MATLAB neural network
Transmit pictures with Base64 encoding
UE4 call DLL
Visual Studio (VS) shortcut keys
[rust notes] 05 error handling
GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库
VIM learning notes from introduction to silk skating
[cloud native] introduction and use of feign of microservices
Kunlunbase meetup is waiting for you!
UE4 source code reading_ Bone model and animation system_ Animation process
Advanced OSG collision detection
Data analysis exercises
[RPC] RPC remote procedure call
梯度下降法求解BP神经网络的简单Demo

