当前位置:网站首页>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”>
边栏推荐
- Alibaba canal actual combat
- URL backup 1
- 【Rust笔记】06-包和模块
- 详解sizeof、strlen、指针和数组等组合题
- Downward compatibility and upward compatibility
- 二进制转十进制,十进制转二进制
- [MySQL] MySQL Performance Optimization Practice: introduction of database lock and index search principle
- Markdown learning
- Alibaba canaladmin deployment and canal cluster Ha Construction
- Chocolate installation
猜你喜欢

Image processing 8-cnn image classification

二进制转十进制,十进制转二进制

Deep parsing (picture and text) JVM garbage collector (II)

简易入手《SOM神经网络》的本质与原理
![[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](/img/76/6561a78b7f883a0e75a53e037153c3.jpg)
[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

Monotonic stack -42 Connect rainwater

单调栈-503. 下一个更大元素 II

Alibaba canal actual combat
![[RPC] RPC remote procedure call](/img/dc/872204ea47fcff04cdb72e18a2a4ef.jpg)
[RPC] RPC remote procedure call

Chocolate installation
随机推荐
How to deal with the core task delay caused by insufficient data warehouse resources
796 · 开锁
Huawei interview summary during the epidemic
Unity editor expansion - scrolling list
注解简化配置与启动时加载
Dom4j遍历和更新XML
Osgearth target selection
MySQL containerization (1) docker installation MySQL
[K & R] Chinese Second Edition personal questions Chapter1
Mxone Pro adaptive 2.0 film and television template watermelon video theme apple cmsv10 template
[concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
redis集群系列四
UE4 plug in development
Message pack in C deserializes array objects
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
【Rust 笔记】08-枚举与模式
Collection interface
数据库原理期末复习
Sequence of map implementation classes
Redis data structure

