【发布时间】:2013-06-11 01:17:33
【问题描述】:
我有以下控制器
@Controller
@RequestMapping("/adwords")
public class AdwordsController
{
@RequestMapping(method = RequestMethod.GET)
public ModelAndView showForm(@ModelAttribute(Const.ADWORDS_COMMAND) AdwordsCommand adwordsCommand, BindingResult result)
throws HttpSessionRequiredException
{
this.checkSessionExpired();
ModelAndView mav = new ModelAndView("adwords/adwordsRequest");
if(adwordsCommand == null)
adwordsCommand = new AdwordsCommand();
User user = this.getUser();
adwordsCommand.setEmail(user.getEmail());
mav.addObject(Const.ADWORDS_COMMAND, adwordsCommand);
return mav;
}
}
映射正确:
13:17:49,276 INFO RequestMappingHandlerMapping:185 - Mapped "{[/adwords],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView pl.ifirma.domeny.controller.adwords.AdwordsController.showForm(java.lang.String,org.springframework.validation.BindingResult) throws org.springframework.web.HttpSessionRequiredException
但是当我在浏览器中输入 URL 时,我得到 302 代码并且服务器立即重定向到应用程序的主页。任何人都可以帮忙吗?为什么服务器不返回 200 或至少 404?
亚当
@评论: 此类代码的行为完全相同。
@Controller
@RequestMapping("/adwords")
public class AdwordsController
{
@RequestMapping(method = RequestMethod.GET)
public ModelAndView showForm(@ModelAttribute(Const.ADWORDS_COMMAND) AdwordsCommand adwordsCommand, BindingResult result)
{
ModelAndView mav = new ModelAndView("adwords/adwordsRequest");
if(adwordsCommand == null)
adwordsCommand = new AdwordsCommand();
User user = this.getUser();
adwordsCommand.setEmail(user.getEmail());
mav.addObject(Const.ADWORDS_COMMAND, adwordsCommand);
return mav;
}
}
我想知道这个奇怪的重定向是否可能是由一些弹簧配置引起的,但是在哪里检查呢?并且只在项目中出现问题的地方。
【问题讨论】:
-
this.checkSessionExpired() 方法中有什么?
-
这与问题 100% 无关 - 已检查。
-
也许不是。你有日志吗?
-
这无关紧要,因为当我删除它时,什么都没有改变......有趣的是没有该行为的日志(重定向)。
-
这个 checkSessionExpired 方法实际上很可能与“抛出 HttpSessionRequiredException”和 302 错误有关。最好仔细检查这个方法!
标签: java spring controller mapping http-status-code-302