@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:
Redirect
- In general, the controller method returns a value of type String name are treated as a logical view
- 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
- redirect: success.jsp: will complete a redirect operation to success.jsp
- 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: