我在重定向页面时遇到问题。
控制器:
@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>
的web.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>
没有瓷砖就是一切都好。但是,当我配置调度程序使用磁贴时,重定向不起作用,我不知道如何解决它。
答案 0 :(得分:3)
解决方案:
我必须返回tile的名称而不是jsp文件。感谢jerome。