当前位置:网站首页>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”>
边栏推荐
- Location of package cache downloaded by unity packagemanager
- Visual Studio (VS) shortcut keys
- Constraintlayout's constraintset dynamically modifies constraints
- Unity editor expansion - window, sub window, menu, right-click menu (context menu)
- Chocolate installation
- Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
- [rust notes] 07 structure
- Dealing with duplicate data in Excel with xlwings
- [rust notes] 06 package and module
- 【Rust笔记】06-包和模块
猜你喜欢
OpenGL learning notes
matlab神经网络所有传递函数(激活函数)公式详解
[concurrent programming] explicit lock and AQS
Visual Studio (VS) shortcut keys
Simple demo of solving BP neural network by gradient descent method
Drawing maze EasyX library with recursive backtracking method
[concurrent programming] concurrent tool class of thread
JS ternary operator - learning notes (with cases)
梯度下降法求解BP神经网络的简单Demo
Annotations simplify configuration and loading at startup
随机推荐
Jupyter remote server configuration and server startup
Monotonic stack -84 The largest rectangle in the histogram
Development material set
796 · unlock
[concurrent programming] explicit lock and AQS
数据库原理期末复习
Pit & ADB wireless debugging of vivo real machine debugging
Message queue for interprocess communication
Osgearth target selection
JS ternary operator - learning notes (with cases)
VIM learning notes from introduction to silk skating
Drawing maze EasyX library with recursive backtracking method
Eating fruit
Analysis of Alibaba canal principle
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
Binary to decimal, decimal to binary
[concurrent programming] synchronization container, concurrent container, blocking queue, double ended queue and work secret
Advanced OSG collision detection
Concurrent programming (VI) ABA problems and solutions under CAS
[redis] redis persistent RDB vs AOF (source code)