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 ...
随机推荐
- c实现swap函数陷阱
swap函数陷阱 使用c实现一个交换两个数的函数,代码很简单: void swap(int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; } 只有3行代码,且 ...
- python子线程退出
def thread_func(): while True: #do something #do something #do something t=threading.Thread(target = ...
- C4D中python初探
use_name = input('请输入账号') password = input('请输入密码') if use_name == 'alex' and password == 'alex3714' ...
- springcloud eureka server 检测 eureka client 状态
import com.netflix.discovery.shared.Applications; import com.netflix.eureka.EurekaServerContextHolde ...
- 2019-6-23-WPF-解决弹出模态窗口关闭后,主窗口不在最前
title author date CreateTime categories WPF 解决弹出模态窗口关闭后,主窗口不在最前 lindexi 2019-06-23 11:48:38 +0800 20 ...
- js隐式类型转换,预编译、递归、作用域,作用域链、闭包、立即执行函数、继承圣杯模式
隐式类型转换 调用Number()当有运算符(加减乘除,求余)时,会调用Number()转为数字再运算,除了 加 当 有字符串时就变身成拼接Boolean();String(); typeof()st ...
- soj116 快乐串
题意:定义一个串是k-happy的:对于所有的Ai,都有Aj(j!=i),使得|Ai-Aj|<=k. 问使得原串至少存在一个长度>=m的连续子串是k-happy的最小的k? 标程: #in ...
- PL/SQL创建用户
步骤一:新建 步骤二:填写信息 对应SQL代码 -- Create the user create user WENT identified by "longrise" defau ...
- 异或前缀和——cf1186C
很思维的题,b的1个数和c的1个数相差为偶数时,必定有偶数个不同 反之必定有奇数个不同 #include <iostream> #include <cstdlib> #incl ...
- python相关软件安装流程图解——MySQL 8.0.13安装教程(windows 64位)——MYSQL依赖的软件——MYSQL必须的系统DLL插件——MYSQL真正的安装
https://www.mysql.com/https://www.mysql.com/downloads/https://dev.mysql.com/downloads/windows/https: ...