gpt4 book ai didi

java - Spring MVC + Apache tile,表单验证和重定向

转载 作者:行者123 更新时间:2023-12-04 05:39:36 25 4
gpt4 key购买 nike

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

Controller :

@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;

}

}

调度程序小服务程序:
<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>

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

最佳答案

解决方案:

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

关于java - Spring MVC + Apache tile,表单验证和重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11421695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com