springboot实现转发和重定向
1、转发
方式一:使用 "forword" 关键字(不是指java关键字),注意:类的注解不能使用@RestController 要用@Controller
@RequestMapping(value="/test/test01/{name}" , method = RequestMethod.GET)
public String test(@PathVariable String name) {
return "forword:/ceng/hello.html";
}
方式二:使用servlet 提供的API,注意:类的注解可以使用@RestController,也可以使用@Controller
@RequestMapping(value="/test/test01/{name}" , method = RequestMethod.GET)
public void test(@PathVariable String name, HttpServletRequest request, HttpServletResponse response) throws Exception {
request.getRequestDispatcher("/ceng/hello.html").forward(request,response);
}
2、重定向
方式一:使用 "redirect" 关键字(不是指java关键字),注意:类的注解不能使用@RestController,要用@Controller
@RequestMapping(value="/test/test01/{name}" , method = RequestMethod.GET)
public String test(@PathVariable String name) {
return "redirect:/ceng/hello.html";
}
方式二:使用servlet 提供的API,注意:类的注解可以使用@RestController,也可以使用@Controller
@RequestMapping(value="/test/test01/{name}" , method = RequestMethod.GET)
public void test(@PathVariable String name, HttpServletResponse response) throws IOException {
response.sendRedirect("/ceng/hello.html");
}
使用API进行重定向时,一般会在url之前加上:request.getContextPath()
springboot实现转发和重定向的更多相关文章
- spring mvc 请求转发和重定向(转)
spring mvc controller间跳转 重定向 传参 url:http://zghbwjl.blog.163.com/blog/static/12033667220137795252845/ ...
- Servlet中转发和重定向的区别
Servlet中页面的跳转有两种方式:转发和重定向. 1.转发和重定向的区别 ①转发是服务器行为,重定向是客户端行为. ②转发是浏览器发生了一次请求,重定向至少是两次请求. ③转发地址栏中的url不会 ...
- JavaWeb学习之转发和重定向、会话技术:cookie、session、验证码实例、URLConnection使用(下载网页)(4)
1.转发和重定向 HttpServletResponse response 转发: RequestDispatcher dispatcher = request.getRequestDispatche ...
- spring mvc 请求转发和重定向
spring mvc controller间跳转 重定向 传参 url:http://zghbwjl.blog.163.com/blog/static/12033667220137795252845/ ...
- servlet的转发与重定向
转发和重定向都能让浏览器获得另外一个URL所指向的资源,但两者的内部运行机制有着很大的区别. 1.转发:有两种方式获得转发对象(RequestDispatcher):一种是通过HttpServletR ...
- http页面转发和重定向的区别
一.调用方式 我们知道,在servlet中调用转发.重定向的语句如下:request.getRequestDispatcher("new.jsp").forward(request ...
- jsp:和属性相关的方法,请求的转发,重定向
jsp中与属性相关的方法: 方法: void setAttribute(String name, Object o): 设置属性 Object getAttribute(String name):获取 ...
- 定向转发和重定向实现 <select >下拉表单数据传送
定向转发的特点: (1). 实行转发时浏览器上的网址不变 (如果你这点忽视了,那你就要接受我无尽的鄙视吧! 哇咔咔~~~) (2). 实行转发时 : 只有一次请求. 不信,看这下面的 ...
- [drp 7]转发和重定向的区别
导读:类似于response.sendRedirect(request.getContextPath()+"/servlet/item/SearchItemServlet");和r ...
随机推荐
- Django中的HttpResponse和JsonResponse
Django中的HttpResponse和JsonResponse 我们在编写一些借口函数的时候,经常需要给调用者返回json格式的数据,那么如何返回可直接解析的数据呢? 首先第一种方式: from ...
- CVE-2017-3248简单复现
我是这样操作的 目标跟windows在一个段,linux是另一个段的,我的虚拟机 windows主机上 `java -cp ysoserial.jar ysoserial.exploit.JRMPLi ...
- 剑指offer——13矩阵中的路径
题目描述 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径.路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子.如果一条路径经过了矩阵中 ...
- IDEA @Autowired dao大红波浪线
SptingBoot+Mybatis开发通常在dao层的注解是@Mapper 这样每次在ServiceImpl层加注解@Autowired时,注入的dao总是波浪线烦人,其实并没有错,只是idea你太 ...
- 查看Linux服务器公网IP
参考:https://www.cnblogs.com/pyyu/p/8545896.html 方法1:curl ifconfig.me 方法2:curl cip.cc
- Ubuntu16.04下安装Visual Studio Code
sudo add-apt-repository ppa:ubuntu-desktop/ubuntu-make sudo apt-get update sudo apt-get install ubun ...
- JS随机产生颜色
<script> function selectForm(lowerValue,upperValue){ var choices=upperValue-lowerValue+1; retu ...
- Fence
Fence 有一个长度为n的\([1,n]\)墙,有k位工人,第i位工人有参数\(s_i,p_i,l_i\),意思该位工人可以刷包含\(s_i\)的长度小于等于\(l_i\)的区间,报酬为区间长度乘以 ...
- Java中的API方法总结
API方法总结 File file = new File(path); #创建文件对象,指向一个目录 file.exists() #判断目录或者文件是否存在 File[] files = file.l ...
- a^a^a^a^a^a^a^a^a
a^a^a^a是从前向后算,也就是a^(a^3)