我试图在Angular.js中使用post方法调用名为ant/talk
的uri。
在我的代码中,我使用javascript中的$http.post
方法调用了数据。
$http.post('ant/create', {
content : $scope.content,
type : chatType,
point : point
}).then(function(response) { /* if successful request */ }
然而,在春季控制器刚告诉我MissingServletRequestParameterException
@Controller
@RequestMapping("/ant/*")
public class AntTalkCont {
....
@RequestMapping(value = "/create", method = RequestMethod.POST, produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public String createProcess(HttpServletRequest request, Locale locale, Model model
, @RequestParam("content") String content) {
String content2 = request.getParameter("content");
logger.debug("content = {}", content);
logger.debug("content by request = {}", content2);
....
但我在上面的java控制器中声明@RequestParam
,弹簧控制器抛出了该异常。虽然我删除了RequestParam
注释并使用了request.getParameter也获得了null
值。
我可以在这个ant/create?content='+$scope.content
上添加内容,但$scope.content
可以超过512个字节,所以我想在post请求中使用data
个对象。
在弹簧控制器中,我该如何正确修理?
这是完整的堆栈跟踪
16:59:17.546 [http-apr-30802-exec-80] DEBUG o.s.w.s.m.m.a.ServletInvocableHandlerMethod - 解析参数时出错 [3] [type = java.lang.String] HandlerMethod详细信息:Controller [kr.stocktalk.webchat.cont.AntTalkCont]方法[公众 java.lang.String中 kr.stocktalk.webchat.cont.AntTalkCont.createProcess(javax.servlet.http.HttpServletRequest,java.util.Locale中,org.springframework.ui.Model,java.lang.String中)]
org.springframework.web.bind.MissingServletRequestParameterException: 必需的字符串参数'内容'不在场 org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:195) 〜[spring-web-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:104) 〜[spring-web-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) 〜[spring-web-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161) [spring-web-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) [spring-web-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) [spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) [spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) [spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) [spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) [spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) [servlet-api.jar:na] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.0.RELEASE.jar:4.3.0.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [servlet-api.jar:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.24] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.24] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.0.24] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.24] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.24] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) [catalina.jar:8.0.24] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.24] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [catalina.jar:8.0.24] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [catalina.jar:8.0.24] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.24] at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617) [catalina.jar:8.0.24] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.24] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [catalina.jar:8.0.24] at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-coyote.jar:8.0.24] at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:668) [tomcat-coyote.jar:8.0.24] at org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.doRun(AprEndpoint.java:2503) [tomcat-coyote.jar:8.0.24] at org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:2492) [tomcat-coyote.jar:8.0.24] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_65] at java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_65] at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.24] at java.lang.Thread.run(Thread.java:745) [NA:1.8.0_65]