长参数不存在错误

时间:2017-04-28 10:55:45

标签: jsp spring-boot

我收到一个奇怪的错误,我看不出原因...因为它所说的无法找到的ID位于URL:http://192.168.160.128:8080/deleteproposal/4并且我有类似的requestMethod工作正常......

异常:org.springframework.web.bind.MissingServletRequestParameterException:必需长参数'id'不存在         网址失败:http://192.168.160.128:8080/deleteproposal/4         异常消息:必需长参数'id'不存在

        org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:251)

        org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:96)

        org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:99)

        org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)

        org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128)

        org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)

        org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832)

        org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743)

        org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)

        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961)

        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)

        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)

        org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)

        javax.servlet.http.HttpServlet.service(HttpServlet.java:622)

        org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)

        javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)

        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)

        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316)

        org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126)

        org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:96)

        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)

        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)

        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

        org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)

        org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)

        org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)

        org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)

        org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)

        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)

        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

        org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)

        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)

        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

        org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)

        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)

        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

        org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)

        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)

        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

        org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)

        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

        org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)

        org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)

        org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)

        org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)

        org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)

        org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)

        org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

        org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)

        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)

        org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)

        org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)

        org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)

        org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)

        java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

        java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

        org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

        java.lang.Thread.run(Unknown Source)

控制器还没有做任何事......

@RequestMapping(value="/deleteproposal/{id}", method=RequestMethod.GET)
public ModelAndView deleteProposal(ModelAndView modelAndView, @RequestParam(value ="id") Long id) {

    System.out.println("!!!!: PROPOSAL CONTROLLER: DELETE id : ");

    return modelAndView;
}

jsp是正常的......

<c:forEach var="proposal" items="${allproposals}">
            <tr>
                <td>${proposal.id}</td>
                <td><span class="label label-warning">${proposal.proposalType}</span></td>
                <td class="hidden-sm">
                    <a href="${contextRoot}/viewonestatus/${proposal.statusUpdate.id}">${proposal.functionality}</a>
                </td>
                <td><fmt:formatDate pattern="EEEE',' d ' de ' MMMM ' de 'y" value="${proposal.release}" /></td>
                <td>
                    <a href="${contextRoot}/deleteproposal/${proposal.id}">
                        <button class="btn-u" type="button" >Borrar</button>
                    </a> 
                </td>
                <td>
                    <a href="${contextRoot}/assignonevotes/${proposal.id}">
                        <button class="btn-u" type="button">Modificar</button>
                    </a>
                </td>
            </tr>
        </c:forEach>

1 个答案:

答案 0 :(得分:3)

要将方法参数名称与URI模板变量(/ deleteproposal / {id})名称匹配,请使用@PathVariable(value="id")代替@RequestParam(value ="id")