2

我在重定向页面时遇到问题。

控制器:

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(@Valid User user,
            BindingResult result) {

        if (result.hasErrors()) {

                    return "userForm";

                    **It will show error - Could not resolve view with name 'userForm' in servlet with name 'dispatcher'**


                    return "redirect:user.htm";

                    **It will redirect page but without error messages**                                                    

        } else {
           **same problem here**
            return "userResult";
        }
    }

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView initForm(ModelAndView model) {
        User us = new User();
        model.addObject("user", us);
        return model;

    }

}

调度程序-servlet:

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass">
        <value>
            org.springframework.web.servlet.view.tiles2.TilesView
        </value>
    </property>
</bean>
<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles.xml</value>
        </list>
    </property>
</bean>

网页.xml:

 <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

没有瓷砖一切都好。但是当我将调度程序配置为使用磁贴时,重定向不起作用,我不知道如何修复它。

4

1 回答 1

3

解决方案:

我必须返回瓷砖的名称而不是 jsp 文件。感谢杰罗姆。

于 2012-07-13T12:47:37.807 回答