当前位置:网站首页>请求参数的发送和接收
请求参数的发送和接收
2022-07-03 08:35:00 【緈福的街口】
一、请求参数
- 请求参数是指浏览器通过请求向Tomcat提交的数据
- 请求参数通常是用户输入的数据,待Servlet进行处理
- 参数名1=值1&参数名2=值2
二、请求参数的发送和接收
html页面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>信息登记表</title>
</head>
<body>
<h1>信息登记表</h1>
<form action="/FirstServlet/sample">
<table>
<tr>
<td>姓名:</td>
<td><input name="name"/></td>
</tr>
<tr>
<td>电话:</td>
<td><input name="mobile"/></td>
</tr>
<tr>
<td>性别:</td>
<td>
<select name="sex">
<option value="male">男</option>
<option value="female">女</option>
</select>
</td>
</tr>
<tr>
<td>爱好:</td>
<td>
<input type="checkbox" name="hobby" value="Swimming"/>游泳
<input type="checkbox" name="hobby" value="Speech"/>演讲
<input type="checkbox" name="hobby" value="Reading"/>读书
<input type="checkbox" name="hobby" value="Program"/>编程
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="提交">
</td>
</tr>
</table>
</form>
</body>
</html>
java页面
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>");
}
}
请求参数的提交
输出
三、Get和Post请求
- Get方式是将数据通过在URL附加数据显性向服务器发送数据(常用于不包含敏感信息的查询功能)
- Post方式会将数据存放在“请求体”中隐性向服务器发送数据(用于安全性较高的功能或者服务器的“写”操作)
1、网络数据区别
(1)Get请求

(2)Post请求

2、处理方法不同,呈现效果不同
(1)Get请求
// 处理get请求
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请求
// 处理post请求
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”>
边栏推荐
- Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)
- Ue5 opencv plug-in use
- 【Rust笔记】06-包和模块
- Use of ue5 QRcode plug-in
- Simply start with the essence and principle of SOM neural network
- Redis cluster series 4
- Sequence of map implementation classes
- Cesium for unreal quick start - simple scenario configuration
- Eating fruit
- Golang time format sorting
猜你喜欢

Chocolate installation

Introduction to Base64 coding

Unity editor expansion - draw lines

Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial

【更新中】微信小程序学习笔记_3
![[redis] redis persistent RDB vs AOF (source code)](/img/57/b6a86c49cedee31fc00dc5d1372023.jpg)
[redis] redis persistent RDB vs AOF (source code)
![[RPC] RPC remote procedure call](/img/dc/872204ea47fcff04cdb72e18a2a4ef.jpg)
[RPC] RPC remote procedure call

C course design employee information management system

Display terrain database on osgearth ball

Base64 and base64url
随机推荐
简易入手《SOM神经网络》的本质与原理
Mall management system of database application technology course design
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
Why can void * be a general pointer
OpenGL learning notes
2021-10-19
Gradle's method of dynamically modifying APK package name
Creation of osgearth earth files to the earth ------ osgearth rendering engine series (1)
Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
jupyter远程服务器配置以及服务器开机自启
Initial unity
【K&R】中文第二版 个人题解 Chapter1
Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données
UE4 plug in development
Unity learning notes
Pit & ADB wireless debugging of vivo real machine debugging
Mysql容器化(1)Docker安装MySQL
Unity4.3.1 engine source code compilation process
How to deal with the core task delay caused by insufficient data warehouse resources
Redis的数据结构

