在spring mvc中重定向页面

时间:2015-04-13 05:26:51

标签: spring jsp spring-mvc

我有一个显示所有产品的产品页面 home.jsp

<a class="campaign" href="page/dynamic/product1">

控制器

@RequestMapping(value="/page/dynamic/{pagename}")
public ModelAndView loadProductPage(ModelMap model, @PathVariable("pagename") String pagename) {
    model.addAttribute("productname",pagename);
    return new ModelAndView("products/"+pagename+"/"+pagename);
}

它被重定向到product1页面。 Product1页面有一个名为features的链接 product1.jsp

<li><a href="/page/loadpage/product1/features">Features</a></li>

控制器

@RequestMapping(value="/page/loadpage/{choosedProduct}/{linkChoosed}")
public ModelAndView loadProductMenuPages(ModelMap model, @PathVariable("linkChoosed") String linkChoosed, @PathVariable("choosedProduct") String choosedProduct) {
    System.out.println("Loading links here");
    System.out.println("cones gere");
    System.out.println("Product Choosed" + choosedProduct);
    System.out.println("Link Choosed" + linkChoosed);
    return new ModelAndView("products/"+choosedProduct+"/"+linkChoosed);
}

它没有被重定向到“功能页面”,但会引发错误:

  

HTTP状态404 - /controller/WEB-INF/views/products/loadpage/loadpage.jsp

我需要做什么才能重定向到功能页面?

修改 在评论中添加servlet-context.xml

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>

1 个答案:

答案 0 :(得分:0)

In your configuration file please configure below tag

    <bean id="PageRedirect" 
       class="org.springframework.web.servlet.view.RedirectView">
           <property name="url" value="RedirectPage.jsp" />
    </bean>

And in your controller 
    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
        HttpServletResponse response) throws Exception {

        return new ModelAndView("PageRedirect");

    }