右键 open Type Hierarchy
OPTIONS用于返回服务器支持的 HTTP Method
POST用于将指定的资源提交到服务器进行处理
GET用于从指定的资源请求数据
PUT用于上传指定资源
DELETE用于删除指定的资源
HEAD与GET方法相同,但是返回的只是HTTP的包头,不会返回文档的主体,一般在浏览器中输入网址访问资源都是通过GET方法;
在表单提交的时候可以通过method属性指定提交方式是get或者post,默认的提交方式是。
修改LoginServlet.java文件为:
package com.jikexueyuan.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public classLoginServlet extendsHttpServlet {
//点击 public class LoginServlet extends HttpServlet左边的警告 按钮 点击Add generated serial version ID 生成以下一行代码:序列号版本ID,用于序列化和反序列化
/**
*
*/
private staticfinal long serialVersionUID = 6520550639750164887L;
//@Override
// protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// String userName = req.getParameter("uname");
// String password = req.getParameter("upwd");
//
// System.out.println("用户名 ==》 " + userName);
// System.out.println("密码 ==》 " + password);
// }
@Override
protectedvoid doGet(HttpServletRequestreq, HttpServletResponse resp)throws ServletException,IOException {
System.out.println("======进入doGet方法======");
String userName =req.getParameter("uname");
String password =req.getParameter("upwd");
System.out.println("用户名 ==》 "+ userName);
System.out.println("密码 ==》 "+ password);
}
@Override
protectedvoid doPost(HttpServletRequestreq, HttpServletResponse resp)throws ServletException,IOException {
System.out.println("======进入doPost方法======");
String userName =req.getParameter("uname");
String password =req.getParameter("upwd");
System.out.println("用户名 ==》 "+ userName);
System.out.println("密码 ==》 "+ password);
}
}
打开浏览器访问
login.jsp方法为post
eclipse控制台
======进入doPost方法======
用户名 ==》 developer
密码 ==》 111111
修改 login.jsp方法为get
eclipse控制台
======进入doGet方法======
用户名 ==》 developer
密码 ==》 111111
浏览器会看到输入的用户名和密码
http://localhost:8080/JSPStudy/loginServlet?uname=developer&upwd=111111&Login=%E6%8F%90%E4%BA%A4
@Override
protectedvoid doGet(HttpServletRequestreq, HttpServletResponse resp)throws ServletException,IOException {
System.out.println("======进入doGet方法======");
doPost(req,resp);
}