【问题标题】:unable to direct request from one war to another war using Spring MVC无法使用 Spring MVC 将请求从一场战争直接转移到另一场战争
【发布时间】:2014-08-26 18:06:31
【问题描述】:

在我部署在 tomcat 上的项目中,有两个 Wars。我必须在 UI 操作上将请求从一场战争重定向到另一场战争。 它目前基于 Spring MVC 架构。所以我在第一次战争中添加了这段代码,将请求重定向到我的另一场战争,但无法重定向。

@Controller
@RequestMapping(value = "/monetize")
public class MyFirstWarController {
    private static final Logger logger = LoggerFactory.getLogger(MyFirstWarController.class);

    @Autowired
    private ServletContext servletContext;

    @RequestMapping(value = "/dashboard", method = RequestMethod.GET)
    public String showConsumerInterests(HttpServletRequest request, Model model) {
        //WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());
        logger.info("In the First War Servlet Context");

        servletContext = servletContext.getContext("/monetize");
        return "monetize/dashboard";
    }

} 

我正在尝试访问我的第二次战争的控制器,在那里我为请求 http://MyLocalHost:8080/monetize/dashboard 提供了 MVC 控制器,并具有与上述类似的控制器。 我需要在 ViewResolver 中提供什么吗?我在网上找不到任何解决方案。

【问题讨论】:

标签: spring spring-mvc


【解决方案1】:

在这种情况下,您应该在控制器的返回值中添加 redirect: 前缀。

例如:

@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
public String showConsumerInterests(HttpServletRequest request, Model model) {
    //any logic
    return "redirect:http://localhost:8080/monetize/dashboard";
}

同时检查this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-15
    • 2015-03-19
    • 1970-01-01
    • 2018-08-11
    • 2012-04-28
    • 2020-01-06
    相关资源
    最近更新 更多