[英]Spring cannot resolve view within servlet
I've added a new method/mapping to one of my servlets: 我已经为我的一个servlet添加了一个新的方法/映射:
@RequestMapping(value = "/user/prefs/order", method = RequestMethod.POST)
public void updateUsersPrefs(@RequestBody Map<String, ArrayList> body, HttpServletRequest request) {
...
}
but when I send a request to this url I get a 500 Internal Server Error, with the following error message: 但是当我向此URL发送请求时,我收到500内部服务器错误,并显示以下错误消息:
javax.servlet.ServletException: Could not resolve view with name 'user/prefs/order' in servlet with name 'appfinder'
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1029)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
I cannot for the life of me see why this is being reported. 我不能为我的生活看到为什么这是报道。 Can anyone help with this?
有人能帮忙吗? I there is anymore information that I could provide, please let me know.
我已经提供了更多信息,请告诉我。
Thanks! 谢谢!
Spring treats @RequestMapping
methods with void
return type in the following manner : Spring 以下列方式处理带有
void
返回类型的@RequestMapping
方法:
void
- if the method handles the response itself (by writing the response content directly, declaring an argument of typeServletResponse
/HttpServletResponse
for that purpose) or if the view name is supposed to be implicitly determined through aRequestToViewNameTranslator
(not declaring a response argument in the handler method signature).void
- 如果方法处理响应本身(通过直接编写响应内容,为此目的声明类型为ServletResponse
/HttpServletResponse
的参数)或者是否应该通过RequestToViewNameTranslator
隐式确定视图名称(不声明响应参数)处理程序方法签名)。
Therefore since there is no HttpServletResponse
parameter to this method, Spring assumes that you would like the view name to be determined through a RequestToViewNameTranslator
. 因此,由于此方法没有
HttpServletResponse
参数,因此Spring假定您希望通过RequestToViewNameTranslator
确定视图名称。
If you do not specify a particular RequestToViewNameTranslator
to use in your context, then the default implementation kicks in which will : 如果您没有指定要在您的上下文中使用的特定
RequestToViewNameTranslator
,那么默认实现将启动 :
simply transforms the URI of the incoming request into a view name.
只需将传入请求的URI转换为视图名称即可。
If you don't want the URI of the incoming request to be used as the view name, you have a few options: 如果您不希望将传入请求的URI用作视图名称,则可以使用以下几个选项:
RequestToViewNameTranslator
with the behavior you would like RequestToViewNameTranslator
HttpServletResponse
parameter to this method if you would like to write to the response directly rather than View resolution take place. HttpServletResponse
参数。 String
, View, or
ModelAndView` to be able to specify the view or view name within the method. String
, View, or
ModelAndView`,以便能够在方法中指定视图或视图名称。 I had this problem, and the reason was I was using tiles framework and did not mention the view name in tiles-def.xml. 我有这个问题,原因是我使用的是tile框架,并没有在tiles-def.xml中提到视图名称。 After configuring tiles-def.xml had the problem solved.
配置完tile-def.xml之后问题就解决了。
I also had this problem. 我也有这个问题。 I solved it by using the @ResponseBody annotation.
我使用@ResponseBody注释解决了它。
Like this: 像这样:
@RequestMapping(value = "/user/prefs/order", method = RequestMethod.POST)
@ResponseBody
public void updateUsersPrefs(@RequestBody Map<String, ArrayList> body, HttpServletRequest request) {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.