<强> 1,转发强>
方式一:使用“丰华”关键字(不是指java关键字),注意:类的注解不能使用@RestController要用@ controller
@RequestMapping (value=" https://www.yisu.com/test/test01/{名称}”、方法=RequestMethod.GET) 公共字符串测试(@PathVariable字符串名称){ 返回“丰华:/曾/hello.html”; }
方式二:使用servlet提供的API,注意:类的注解可以使用@RestController,也可以使用@ controller
@RequestMapping (value=" https://www.yisu.com/test/test01/{名称}”、方法=RequestMethod.GET) 公共空白测试(@PathVariable字符串名称、HttpServletRequest请求HttpServletResponse响应){抛出异常 request.getRequestDispatcher(“/曾/hello.html”) forward格式(请求、响应); }
<强> 2,重定向强>
方式一:使用“定向”关键字(不是指java关键字),注意:类的注解不能使用@RestController,要用@ controller
@RequestMapping (value=" https://www.yisu.com/test/test01/{名称}”、方法=RequestMethod.GET) 公共字符串测试(@PathVariable字符串名称){ 返回“重定向:/曾/hello.html”; }
方式二:使用servlet提供的API,注意:类的注解可以使用@RestController,也可以使用@ controller
@RequestMapping (value=" https://www.yisu.com/test/test01/{名称}”、方法=RequestMethod.GET) 公共空白测试(@PathVariable字符串名称,HttpServletResponse响应)抛出IOException { response.sendRedirect(“/曾/hello.html”); }
使用API进行重定向时,一般会在url之前加上:request.getContextPath ()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。