Http请求Get和Post的区别(HttpServlet)

来源:互联网 发布:梨园淘宝城 编辑:程序博客网 时间:2024/06/04 17:53

Http请求分两种形式一种是post,一种是Get,如下是展示案例

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>HttpServletTest</title></head><body><!-- web发请求 默认getget和post的区别是,1、get会把username&password信息带在网址上面2、小于2K,3、速度快优先级高1、post会把username&password信息隐藏起来   相对而言会更安全一些,2、大小没有限制,但是最好小于64K,3、提交会形成队列,所以会慢一点 --><form action="/MyHttpServlet/Three" method="post"> U:<input type="text" name="username"/><input type="submit" value="logon"/></form></body></html>


HttpServlet  服务器

package com.itcast;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 MyHttpServlet extends HttpServlet{private static final long serialVersionUID = 1L;//处理get请求public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException{PrintWriter pw = res.getWriter();pw.println("Sayhi to HttpServlet Get!!");}public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException{System.out.println("Post!!");res.getWriter().println("Sayhi to HttpServlet Post!!");}}


当Html用Post方式提交的时候  页面会返回Sayhi to HttpServlet Post!!

当Html用Get方式提交的时候  页面会返回Sayhi to HttpServlet Get!!




0 0
原创粉丝点击