SpringMVC---Method

GET

平时网页的一些基本的URL都是GET请求的,用于执行查询操作。
但是由于GET中URL是有长度的限制的,而GET会把所有的参数都放在URL中

因此就会有下面的问题:
  • 1 数据都明文暴露,用户可以直接看到
  • 2 数据长度有限制

POST

由于上面GET的缺点,POST正好弥补了这些问题。POST方法把数据都存放在body里面,这样即突破了长度的限制;又保证用户无法直接看到。在使用表单时,比较常用

HEAD请求只会返回首部的信息,不会返回相应体。通常用于测试数据是否存在、当做心跳检测等等。

PUT

与GET相反,用于改变某些内容。

DELETE

删除某些资源

TRACE

可以理解成,我们为了看看一条请求在到达服务前数据发生了什么变化。可以使用这个命令,它会在最后一站返回原始信息,这样就可以观察到中间是否修改过请求。(经常会用于跨站攻击,所以有一定的安全隐患)

OPTIONS

询问服务器支持的方法。

PATCH

这个方法不太常见,是servlet 3.0提供的方法,主要用于更新部分字段。与PUT方法相比,PUT提交的相当于全部数据的更新,类似于update;而PATCH则相当于更新部分字段,如果数据不存在则新建,有点类似于neworupdate。

 

 

配置文件承接一二章

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
 <form action="springMVC/testMethod" method="post">
 <input type="text" name="name"/>
 <input type="submit" value="submit"/>
 </form>

 <form action="springMVC/testGetMethod" method="get">
 <input type="text" name="name"/>
 <input type="submit" value="submitGet"/>
 </form>
 

</body>
</html>

test.java

package com.hdxy.domian;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
/**
 * @author 流年拓荒者
 *
 */
@RequestMapping("springMVC")
@Controller
public class Test {
   final public String SUCCESS="loginSuccess";
   /*常用: 使用method 属性来指定请求方式
     * */
   @RequestMapping(value="testMethod",method=RequestMethod.POST)
   public String test3Method(String name){
    System.out.println("testMethod"+name);   
       return SUCCESS;
   }
   
   @RequestMapping(value="testGetMethod",method=RequestMethod.GET)
   public String test3GetMethod(String name){
    System.out.println("testGetMethod"+name);   
       return SUCCESS;
   }
   @RequestMapping(value="testGetMethod",method={RequestMethod.GET,RequestMethod.POST})
   public String test3PostGetMethod(String name){
    System.out.println("testGetPostMethod"+name);   
       return SUCCESS;
   }
}

 

posted @ 2017-11-20 11:01  流年拓荒者  阅读(1134)  评论(0编辑  收藏  举报
   
在博客右侧,浮出一个微博浮动框