【发布时间】:2016-09-22 08:21:42
【问题描述】:
我在使用 @RequestMapping(method = RequestMethod.POST) 注释向控制器类添加方法时遇到问题。问题是当我添加此方法并启动应用程序时。应用程序无法加载资源(css、JS 等)。在浏览器上我得到: 加载资源失败:服务器响应状态为 405(不允许方法) 在运行日志中,我收到以下消息: org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupported 警告:不支持请求方法“GET”
当我从控制器类中删除此方法时,一切正常。不知道为什么会这样。我确定它与 Dispatcher Servlet 映射中的配置或资源无关,因为没有这种方法,一切都可以正常工作。
由于某些业务需求,我需要使用这种方法,否则是不可能的。
任何机构都可以帮助我确定问题所在。
@Controller
public class InvoiceController
{
@RequestMapping(value = "/index", method = RequestMethod.GET)
public ModelAndView adminPage() {
String username;
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
username = auth.getName(); //get logged in username
username.toUpperCase();
// Logic to build menue based on the Role of the user.
HashMap hm = new HashMap();
OrderItems od = new OrderItems();
ModelAndView model = new ModelAndView();
model.addObject("usr", username);
//Set the object for Menue Links on the Page
model.addObject("mnue", hm);
model.setViewName("index");
model.addObject("odi",od);
return model;
}
@RequestMapping(method = RequestMethod.POST)
public String save(HttpServletRequest request,
HttpServletResponse response,
Model model)
{
System.out.println("Im here in Genaric Post Method");
return null;
}
}
还请注意,我使用的是 Spring Security 配置。和安全有什么关系吗?或者控制器类配置有问题。
提前感谢您的期待。
问候,
D 卡姆兰
【问题讨论】:
标签: java spring spring-mvc