Java – spring MVC relative redirection from httpservletresponse
•
Java
Given this relative redirection to another controller:
@Controller
@RequestMapping("/someController")
public class MyController {
@RequestMapping("/redirme")
public String processForm(ModelMap model) {
return "redirect:/someController/somePage";
}
}
If I'm in the interceptor, how can I simulate the same relative redirection?
public class MyInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,HttpServletResponse response,Object handler) throws Exception
{
response.sendRedirect("/someController/somePage");
return false;
}
}
Now use the interceptor when I really want to access the application COM / deployment / somecontroller / somepage, I will finally visit application com/someController/somePage. Of course, must there be a "spring" solution?
Solution
Translate my comments into answers –
Try using response sendRedirect(request.getContextPath()uri);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
