Table of Contents
The difference between post and get in HTML submission methods (experiment)
1. The difference between post and get
2. Client code
3. Server code
4. Results
Home Web Front-end HTML Tutorial What is the difference between post and get submission methods in html?

What is the difference between post and get submission methods in html?

Jun 24, 2017 pm 02:09 PM
html post the difference submit Way

The difference between post and get in HTML submission methods (experiment)

1. The difference between post and get

Get submission, the submitted information is displayed in the address bar.
Post submission, the submitted information is not displayed in the address bar, but is displayed in the message body.

2. Client code

<!DOCTYPE html><html><head><title>Form.html</title><meta name="keywords" content="keyword1,keyword2,keyword3"><meta name="description" content="this is my page"><meta name="content-type" content="text/html; charset=GB2312"><!--<link rel="stylesheet" type="text/css" href="./styles.css?1.1.11">--></head><body><!--提交方式:get提交。地址栏:http://localhost:9891/?user=abc&psw=123&repsw=123&sex=nan&tech=java&tech=html&country=cnGET /?user=abc&psw=123&repsw=123&sex=nan&tech=java&tech=html&country=cn HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: zh-cn,zu;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2)
Host: localhost:9891
Connection: Keep-Alive


提交方式:POST地址栏:http://localhost:9891/POST / HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: zh-cn,zu;q=0.5
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2)
Host: localhost:9891
Content-Length: 68
Connection: Keep-Alive
Cache-Control: no-cacheuser=hahah&psw=8989&repsw=8989&sex=nv&tech=html&tech=css&country=usa
        
        
        GET提交和POST提交的区别?
        1,
        get提交,提交的信息都显示在地址栏中。
        post提交,提交的信息不显示地址栏中。
        
        2,
        get提交,对于敏感的数据信息不安全。
        post提交,对于敏感信息安全。
        
        3,
        get提交,对于大数据不行,因为地址栏存储体积有限。
        post提交,可以提交大体积数据。 
        
        4,
        get提交,将信息封装到了请求消息的请求行中。
        post提交,将信息封装到了请求体中。
        
        在服务端的一个区别。        如果出现将中文提交到tomcat服务器,服务器默认会用iso8859-1进行解码会出现乱码,
        通过iso8859-1进行编码,在用指定的中文码表解码。即可。
        这种方式对get提交和post提交都有效。 
        
        但是对于post提交方式提交的中文,还有另一种解决办法,就是直接使用服务端一个对象
        request对象的setCharacterEncoding方法直接设置指定的中文码表就可以将中文数据解析出来。
        这个方法只对请求体中的数据进行解码。 
        
        综上所述:表单提交,建议使用post。
        
        
        和服务端交互的三种方式:
        1,地址栏输入url地址。get
        2,超链接。 get3,表单。 get 和  post

        
        如果在客户端进行增强型的校验(只要有一个组件内容是错误,是无法继续提交的。只有全对才可以提交)
        问,服务端收到数据后,还需要校验吗?
        需要,为了安全性。
        为了信息安全,也为了客户端那边不要乱提交数据,客户端和服务端都需要做校验。
        
        如果服务端做了增强型的校验,客户端还需要校验吗?需要,因为要提高用户的上网体验效果,减轻服务器端的压力。        
        -->表单格式化<br><!-- action里面的http协议不能忘记 --><form action="http://localhost:9891" method="post"><!-- 
             cellpadding 属性规定单元边沿与其内容之间的空白。
             注释:请勿将该属性与 cellspacing 属性相混淆,cellspacing 属性规定的是单元之间的空间。
             从实用角度出发,最好不要规定 cellpadding,而是使用 CSS 来添加内边距。         --><table border="1" bordercolor="#00ffff" cellpadding=10 cellspacing=0width=400><!-- 由此可见,<th>和<td>标签都是用于表格单元格显示的。不同的是<th>在单元格中加粗显示。 --><tr><!-- 占两列 --><th colspan="2">注册表单</th></tr><tr><td>用户名称</td><td><input type="text" name="user" value=""><br /></td></tr><tr><td>输入密码</td><td><input type="password" name="pwd" /><br /></td></tr><tr><td>确认密码</td><td><input type="password" name="repwd" /><br /></td></tr><tr><td>选择性别</td><td><input type="radio" name="sex" value="nan" />男 <inputtype="radio" name="sex" value="nv" checked="checked" />女<br /></td></tr><tr><td>选择技术</td><td><input type="checkbox" name="tech" value="java" />JAVA <inputtype="checkbox" name="tech" value="html" />HTML <inputtype="checkbox" name="tech" value="css" />CSS <br /></td></tr><tr><td>选择国家</td><td><select name="country"><option value="none">--选择国家--</option><option value="usa">美国</option><option value="en">英国</option><!-- 默认选择中国 --><option value="cn" selected="selected">中国</option></select></td></tr><tr><th colspan="2"><input type="reset" value="清除数据" /> <inputtype="submit" value="提交数据" /></th></tr></table></form></body></html>
Copy after login

3. Server code

RegServer.java

 1 /** 2  * 
 3  */ 4 package cn.itcast.server; 5  6 import java.io.IOException; 7 import java.io.InputStream; 8 import java.io.PrintWriter; 9 import java.net.ServerSocket;10 import java.net.Socket;11 12 /**13  * @author Fry14  *15  */16 public class RegServer {17 18     /**19      * @param args20      * @throws Exception 
21      */22     public static void main(String[] args) throws Exception {23         24         ServerSocket ss = new ServerSocket(9891);//新建服务端端口25         26         Socket s = ss.accept();//端口监听27         //输出服务器主机地址 ans:0:0:0:0:0:0:0:128         System.out.println(s.getInetAddress().getHostAddress());29         InputStream in = s.getInputStream();//字节输入流,用来接收客户端消息30         byte[] buf = new byte[1024];//1024字节的缓存31         int len = in.read(buf);//将收到的消息读到buf中32         //输出接收到的页面消息 包括消息行  消息头  消息体33         System.out.println(new String(buf,0,len));34         //字符输出,用来存储发送给客户端的消息35         PrintWriter out = new PrintWriter(s.getOutputStream(),true);36         //客户端接收到的消息37         out.println("<font color=&#39;green&#39; size=&#39;7&#39;>注册成功</font>");38         //关闭端口39         s.close();40         ss.close();41     }42 43 }
Copy after login

4. Results

The above is the detailed content of What is the difference between post and get submission methods in html?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

React's Role in HTML: Enhancing User Experience React's Role in HTML: Enhancing User Experience Apr 09, 2025 am 12:11 AM

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

How to set password protection for export PDF on PS How to set password protection for export PDF on PS Apr 06, 2025 pm 04:45 PM

Export password-protected PDF in Photoshop: Open the image file. Click "File"&gt; "Export"&gt; "Export as PDF". Set the "Security" option and enter the same password twice. Click "Export" to generate a PDF file.

HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The difference between H5 and mini-programs and APPs The difference between H5 and mini-programs and APPs Apr 06, 2025 am 10:42 AM

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML: Building the Structure of Web Pages HTML: Building the Structure of Web Pages Apr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

See all articles