Redirect in Spring MVC

后端 未结 8 2210
遇见更好的自我
遇见更好的自我 2020-11-28 11:00

Why can\'t I get this to work in my Controller

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(
    Model model,
    @ModelAttribute(\"fo         


        
相关标签:
8条回答
  • 2020-11-28 11:35

    Axtavt answer is correct.

    This is how your resolver should look like (annotations based):

        @Bean
    UrlBasedViewResolver resolver(){
        UrlBasedViewResolver resolver = new UrlBasedViewResolver();
    
        resolver.setPrefix("/views/");
        resolver.setSuffix(".jsp");
        resolver.setViewClass(JstlView.class);
    
        return resolver;
    }
    

    Obviously the name of your views directory should change based on your project.

    0 讨论(0)
  • 2020-11-28 11:36

    Also note that redirect: and forward: prefixes are handled by UrlBasedViewResolver, so you need to have at least one subclass of UrlBasedViewResolver among your view resolvers, such as InternalResourceViewResolver.

    0 讨论(0)
  • 2020-11-28 11:36

    Try this

    HttpServletResponse response;       
    response.sendRedirect(".../webpage.xhtml");
    
    0 讨论(0)
  • 2020-11-28 11:39

    try to change this in your dispatcher-servlet.xml

    <!-- Your View Resolver -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
        <property name="basenames" value="views" />
        <property name="order" value="1" />
    </bean>   
    <!-- UrlBasedViewResolver to Handle Redirects & Forward -->
    <bean id="urlViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
        <property name="order" value="2" />
    </bean>        
    

    What happens is clearly explained here http://projects.nigelsim.org/wiki/RedirectWithSpringWebMvc

    0 讨论(0)
  • 2020-11-28 11:40

    It is possible to define a urlBasedViewResolver in your properties file:

    excel.(class)=fi.utu.seurantaraporttisuodatin.service.Raportti  
    index.(class)=org.springframework.web.servlet.view.urlBasedView  
    index.viewClass =org.springframework.web.servlet.view.JstlView  
    index.prefix = /WEB-INF/jsp/  
    index.suffix =.jsp
    
    0 讨论(0)
  • 2020-11-28 11:41

    i know this is late , but you should try redirecting to a path and not to a file ha ha

    0 讨论(0)
提交回复
热议问题