我有两个带有两个控制器的JSP页面(每个JSP一个)。
我正试图从登陆jsp转发到appt jsp。我的登陆控制器标记如下:
@Controller
@SessionAttributes("state")
@RequestMapping(value = "/landing")
public class LandingController {
@RequestMapping(value = "/postData", method = RequestMethod.POST)
public String lookup(@ModelAttribute("state") State state, Model model) {
// something useful goes here
return "appt";
}
}
我的ApptController:
从Spring调试日志信息中,我可以看出:
我没有在浏览器中看到新页面,也没有看到Spring尝试将URL与日志中的appt控制器方法匹配。我必须假设appt控制器从未见过请求。
这是我的appt控制器方法(Spring正在执行):
@Controller
@SessionAttributes("state")
@RequestMapping(value="/appt")
public class ApptController {
@RequestMapping(method = RequestMethod.GET)
public String home(@ModelAttribute("state") PAWState state, Model model) {
model.addAttribute("state", state);
return "appt";
}
使用:
return "redirect:/appt"
让我更接近,我明白了:
我看不到的是我的浏览器中的新渲染。我看到了相同的搜索页面。
我错过了什么?
记录(返回“redirect:/ appt”):
12:53:40,451 DEBUG - DispatcherServlet with name 'XServlet' processing POST request for /X/landing/postData]
12:53:40,451 DEBUG - Looking up handler method for path /landing/postData
12:53:40,451 DEBUG - Returning handler method [public java.lang.String x.x.x.x.controller.LandingController.lookup(x.x.x.x.controller.valuebeans.XState,org.springframework.ui.Model) throws x.x.x.x.common.exception.XException]
12:53:40,451 DEBUG - Returning cached instance of singleton bean 'LandingController'
12:53:40,732 DEBUG - Invoking afterPropertiesSet() on bean with name 'redirect:/appt'
12:53:40,732 DEBUG - Rendering view [org.springframework.web.servlet.view.RedirectView: name 'redirect:/appt'; URL [/appt]] in DispatcherServlet with name 'XServlet'
12:53:40,732 DEBUG - Successfully completed request
12:53:40,732 DEBUG - DispatcherServlet with name 'XServlet' processing GET request for [/X/appt]
12:53:40,732 DEBUG - Looking up handler method for path /appt
12:53:40,732 DEBUG - Returning handler method [public java.lang.String x.x.x.x.controller.ApptController.home(x.x.x.x.controller.valuebeans.XState,org.springframework.ui.Model) throws x.x.x.x.common.exception.XException]
12:53:40,732 DEBUG - Returning cached instance of singleton bean 'apptController'
12:53:40,732 DEBUG - Last-Modified value for [/X/appt] is: -1
12:53:40,732 DEBUG - Invoking afterPropertiesSet() on bean with name 'appt'
12:53:40,732 DEBUG - Rendering view [org.springframework.web.servlet.view.JstlView: name 'appt'; URL [/WEB-INF/jsp/appt.jspx]] in DispatcherServlet with name 'XServlet'
12:53:40,732 DEBUG - Added model object 'org.springframework.validation.BindingResult.state' of type [org.springframework.validation.BeanPropertyBindingResult] to request in view with name 'appt'
12:53:40,732 DEBUG - Added model object 'state' of type [x.x.x.x.controller.valuebeans.XState] to request in view with name 'appt'
12:53:40,732 DEBUG - Forwarding to resource [/WEB-INF/jsp/appt.jspx] in InternalResourceView 'appt'
12:53:42,979 DEBUG - No properties file found for [file:/C:/Work/x/WEB-INF/messageSource/content_en_US] - neither plain properties nor XML
12:53:42,979 DEBUG - No properties file found for [file:/C:/Work/x/WEB-INF/messageSource/content_en] - neither plain properties nor XML
12:53:42,979 DEBUG - Loading properties [content.properties]
12:53:43,010 DEBUG - No property editor [java.lang.BooleanEditor] found for type java.lang.Boolean according to 'Editor' suffix convention
12:53:43,026 DEBUG - Successfully completed request
编辑:这是通过Spring 3.1.1使用注释
答案 0 :(得分:0)
如果你确实返回“forward:appt”而不是返回“redirect:appt”,即使使用AJAX请求,事情也应该有效。这是因为重定向导致向客户端发送HTTP重定向状态代码,而不会在响应终止之前呈现视图;而转发导致响应被转发到下一个控制器,并且在响应终止之前呈现相关视图。