Get方法和Post方法传输数据区别:    传送门

  • GET在浏览器回退时是无害的,而POST会再次提交请求
  • GET产生的URL地址可以被Bookmark,而POST不可以
  • GET请求会被浏览器主动cache,而POST不会,除非手动设置
  • GET请求只能进行url编码,而POST支持多种编码方式
  • GET请求参数会被完整保留在浏览器历史记录里,而POST中的参数不会被保留
  • GET请求在URL中传送的参数是有长度限制的,而POST么有
  • 对参数的数据类型,GET只接受ASCII字符,而POST没有限制
  • GET比POST更不安全,因为参数直接暴露在URL上,所以不能用来传递敏感信息
  • GET参数通过URL传递,POST放在Request body中

                                

        

Learn

  一、Get方式直接传参

  二、通过表单Get方式传参

  三、通过表单Post方式传参
 

一、Get方式直接传参

  直接在Url中输入要传参的值

  通过System.out.println()控制台中打印出信息

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
Hello,Gary! <br>
<%
String username = request.getParameter("username");
System.out.println(username);
String password = request.getParameter("password");
System.out.println(password);
%>
</body>
</html>

index.jsp

    usernae: gary
password: 123456

二、通过表单Get方式传参

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
Hello,Gary! <br> 登陆
<form action="login.jsp" method="get">
<input type = "text" name = "username"/>
<input type = "password" name="password"/>
<input type="submit">
</form> </body>
</html>

index.hjsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'login.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
Login.jsp. <br>
</body>
</html>

login.jsp

  method="get"  将传输请求设置为get方式

    <form action="login.jsp" method="get">
<input type = "text" name = "username"/>
<input type = "password" name="password"/>
<input type="submit">
</form>

  用户在登陆的时候账号和密码直接暴露在url中,即使 <input type = "password">也不能阻止我们直接从网页上获取用户密码

三、通过表单Post方式传参

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
Hello,Gary! <br> 登陆
<form action="login.jsp" method="post">
<input type = "text" name = "username"/>
<input type = "password" name="password"/>
<input type="submit">
</form> </body>
</html>

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'login.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head> <body>
Login.jsp. <br>
</body>
</html>

login.jsp

  method="post"  将传输请求设置为post方式

    <form action="login.jsp" method="post">
<input type = "text" name = "username"/>
<input type = "password" name="password"/>
<input type="submit">
</form>

  

JavaWeb_Get和Post方法传输数据区别的更多相关文章

  1. get方法与post方法的区别与js获取url参数的方式

    1.get方法与post方法的区别: 区别一:get重点在从服务器上获取资源,post重点在向服务器发送数据:区别二:get传输数据是通过URL请求,以field(字段)= value的形式,置于UR ...

  2. 无线加密的多种方法及其区别(WEP WPA TKIP EAP)

    无线加密的多种方法及其区别(WEP WPA TKIP EAP) 无线网络的安全性由认证和加密来保证. 认证允许只有被许可的用户才能连接到无线网络: 加密的目的是提供数据的保密性和完整性(数据在传输过程 ...

  3. ThinkPHP的D方法和M方法的区别

    M方法和D方法的区别 ThinkPHP 中M方法和D方法都用于实例化一个模型类,M方法 用于高效实例化一个基础模型类,而 D方法 用于实例化一个用户定义模型类. 使用M方法 如果是如下情况,请考虑使用 ...

  4. 正则表达式中的exec和match方法的区别

    正则表达式中的exec和match方法的区别 字符串的正则方法有:match().replace().search().split() 正则对象的方法有:exec().test() 1.match m ...

  5. Hibernate框架之get和load方法的区别

    我们在学习Hibernate框架时,经常会进行修改,删除操作,对于这些操作,我们都应该先加载对象,然后在执行或删除的操作,那么这里Hibernate提供了两种方法按照主键加载对象,也就是我要说的get ...

  6. [BS-27] 创建NSURL的几个方法的区别

    创建NSURL的几个方法的区别     URL的基本格式 = 协议://主机地址/路径 URL和Path的区别 * URL:统一资源定位符,格式 “协议+主机名称+路径”   例如:[NSURL UR ...

  7. Java线程中yield与join方法的区别

    长期以来,多线程问题颇为受到面试官的青睐.虽然我个人认为我们当中很少有人能真正获得机会开发复杂的多线程应用(在过去的七年中,我得到了一个机会),但是理解多线程对增加你的信心很有用.之前,我讨论了一个w ...

  8. OpenGL的glTexImage2D()与gluBuild2DMipmaps()的使用方法及区别

    OpenGL的glTexImage2D()与gluBuild2DMipmaps()的使用方法及区别 说明:两者的都是生成纹理,即:将载入的位图文件(*.bmp)转换成纹理贴图. 1.glTexImag ...

  9. Java线程中run和start方法的区别

    http://bbs.csdn.net/topics/350206340 Thread类中run()和start()方法的区别如下:run()方法:在本线程内调用该Runnable对象的run()方法 ...

随机推荐

  1. FFmpeg4.0笔记:VS2019编译FFmpeg4.0源码

    0.下载TDM.msys和yasm 1.安装TDM-GCC-64 2.安装msys到TDM-GCC的安装目录中 3.将call "C:\Program Files (x86)\Microso ...

  2. GitHub从小白到熟悉<三>

    上传文件

  3. vscode中eslint插件的配置-prettier

    用vue-cli构建vue项目,会有个eslint代码检测的安装 可vscode自带代码格式化是prettier格式(右键有格式化文件或alt+shift+f) 这时候要在vscode上装一个esli ...

  4. 屏幕的遮挡层,js得到屏幕宽高、页面宽高 (window.screen.availHeight)等--

    window.screen.availWidth 返回当前屏幕宽度(空白空间) ------当手机有输入法的时候,要注意................window.screen.availHeigh ...

  5. Collection接口的子接口——Set接口

    https://docs.oracle.com/javase/8/docs/api/java/util/Set.html public interface Set<E>  extends ...

  6. GoAccess安装

    编译安装 yum install geoip-devel openssl-devel libmaxminddb-devel ncurses-devel bzip2-devel tokyocabinet ...

  7. Git复习(十二)之命令专场

    命令 git init -> 初始化一个git仓库 git clone -> 克隆一个本地库 git pull -> 拉取服务器最新代码 git fetch –p -> 强行拉 ...

  8. 转换byte(十进制)为图形(大小写字母,符号)

    /** * 转换byte(十进制)为字母 */ public static String ByteToLetter (byte[] chars) { String Letter = "&qu ...

  9. ubuntu 创建定时备份pg数据库定时任务

    ubuntu创建定时备份数据库定时任务 一.命令文件 创建db_back.sh #!/bin/bash echo "start backup" /usr/lib/postgresq ...

  10. cmd 创建并写入文件

    一.建立空文件的几种方法1.cd.>a.txtcd.表示改变当前目录为当前目录,即等于没改变:而且此命令不会有输出.>表示把命令输出写入到文件.后面跟着a.txt,就表示写入到a.txt. ...