JSP 只允许 GET、POST 或 HEAD。Jasper 还允许 OPTIONS

405方法不允许

可以发现是经过了方法,但是返回到页面确是405,说明能正常发和收到请求,但是返回页面会报405,于是我们可以利用这点:
即对应的PUT方法和delete方法可以重定向到一个地址然后返回页面,就可以正确的到达页面,这是我目前能想到的方法【当然你也可以降到tomcat7.0及以下,不过不推荐】,记得设置页面的isErrorPage=true,,看看HiddenHttpMethodFilter配置了没有

@Controller
@RequestMapping("/hello")
public class HelloController {

	@RequestMapping(value = "/book/{id}",method = RequestMethod.GET)
	public String get(@PathVariable("id") Integer id) {
		System.out.println("查询"+id+"号图书");
		return "success";
	}
	@RequestMapping(value = "/book",method = RequestMethod.POST)
	public String post() {
		System.out.println("添加图书");
		return "success";
	}
	@RequestMapping(value = "/book/{id}",method = RequestMethod.PUT)
	public String put(@PathVariable("id") Integer id) {
		System.out.println("更新"+id+"号图书");
		return "redirect:/hello/toput";
	}
	@RequestMapping("/toput")
	public String toPutPage() {
		System.out.println("toPutPage");
		return "success";
	}
	@RequestMapping(value = "/book/{id}",method = RequestMethod.DELETE)
	public String delete(@PathVariable("id") Integer id) {
		System.out.println("删除"+id+"号图书");
		return "redirect:/hello/todel";
	}
	@RequestMapping("/todel")
	public String toDelPage() {
		System.out.println("toDelPage");
		return "success";
	}
	
}

你可能感兴趣的:(异常和错误)