In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "Spring MVC controller how to handle 301 jump", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "Spring MVC controller how to handle 301 jump"!
SpringMVC301, 302 Jump
The spring mvc project is a subproject of spring that handles view-level requests.
302 jump is very simple:
@RequestMapping(value = "blog.html")public String rindex() { return "redirect:/blog";}
According to the concept of not repeating the wheel, in fact, 301 jump is also very simple:
@RequestMapping(value = "blog.html")public RedirectView rindex(HttpServletRequest request) { RedirectView redirectView = new RedirectView("/blog"); redirectView.setStatusCode(HttpStatus.MOVED_PERMANENTLY); return redirectView; }
Spring mvc provides a view view specifically designed to handle various redirects.
The jump results are as follows:
Other implementations include:
response.setStatus(301);
response.setHeader("Location", "https://www.xxxx");
Second, Redorect jump to pass parameters
Redorect 3 ways to pass reference
The first one: manual URL splicing
new ModelAndView("redirect:/toList?param1="+value1+"¶m2="+value2);
This has a drawback, that is, the transmission of Chinese may have garbled code problems, need to deal with their own.
Category 2: RedirectAttributes
Here it uses its addAttribute method, this actually redirects you to look at the url after the past, it automatically spells your url for you.
How to use:
public String test(RedirectAttributes attributes)
{
attributes.addAttribute("test", "hello");
return "redirect:/test/test2";
}
ModelAndView with attributes in model
ModelAndView model = new ModelAndView("redirect:/main/index");
model.addObject("userName", userName); //bring userName parameter into controller's RedirectAttributes
return model;
At this point, I believe that everyone has a deeper understanding of "Spring MVC controller how to handle 301 jumps", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.