Big Data learning --SpringMVC @ ResponseBody notes and redirection

@ResponseBody comment

After the addition of the annotation on Handler method, the return value will be in the form of a string in direct response to the browser.

index.jsp label processed:

	<a href="${pageContext.request.contextPath }/testResponseBody">Test ResponseBody</a><br>

Response Handler Method:

/*
 * 在类上添加了@ResponseBody注解之后,Handler的方法的返回值将直接响应给浏览器,
 * 但是前提是在SpringMVC的配置文件中配置了<mvc:annotation-driven></mvc:annotation-driven>
 */
	@ResponseBody
	@RequestMapping("/testResponseBody")
	public String testResponseBody() {
		System.out.println("测试@ResponseBody注解");
		return "success";
	}

Test display page:
Processing page

Redirect

  1. In general, the controller method returns a value of type String name are treated as a logical view
  2. If the string returned with forward: or redirect: prefix, SpringMVC they will have special treatment: forward: and redirect: as an indicator, followed by the string as a URL to handle
  3. redirect: success.jsp: will complete a redirect operation to success.jsp
  4. forward: success.jsp: to success.jsp will complete a forwarding operation

index.jsp label processed:

	<a href="${pageContext.request.contextPath }/testRedirect">Test Redirect</a><br>

Response Handler Method:

	@RequestMapping("/testRedirect")
	public String testRedirect() {
		System.out.println("测试重定向");
//		return "forward:/forward.jsp";
//		return "redirect:/testMap";
		return "redirect:/redirect.jsp";
	}

Test display page:
Display page

Published 37 original articles · won praise 7 · views 667

Guess you like

Origin blog.csdn.net/qq_40394792/article/details/104435564