@RequestParam spring mvc无法正常工作

时间:2017-03-10 01:59:54

标签: spring jsp model-view-controller

当我尝试从我的spring mvc app从@RequestParam获取参数时,我收到此错误:

SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /WEB-INF/views/adminPageImageGallery.jsp (line: 254, column: 88) quote symbol expected
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:291)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:97)
    at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:238)
    at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:169)
    at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:160)
    at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1254)
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1473)
    at org.apache.jasper.compiler.Parser.parse(Parser.java:145)
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244)
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:105)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:201)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:333)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:715)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:460)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:385)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

Mar 10, 2017 2:52:42 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/app] threw exception [/WEB-INF/views/adminPageImageGallery.jsp (line: 254, column: 88) quote symbol expected] with root cause
org.apache.jasper.JasperException: /WEB-INF/views/adminPageImageGallery.jsp (line: 254, column: 88) quote symbol expected
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:291)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:97)
    at org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:238)
    at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:169)
    at org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:160)
    at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1254)
    at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1473)
    at org.apache.jasper.compiler.Parser.parse(Parser.java:145)
    at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244)
    at org.apache.jasper.compiler.ParserController.parse(ParserController.java:105)
    at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:201)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:333)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:715)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:460)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:385)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1347)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

我的控制器是:

@SuppressWarnings("unchecked")
@RequestMapping(value = { "/show-gallery" }, method = RequestMethod.GET )
public ModelAndView all(@RequestParam(value = "page", required = false) String page, HttpServletRequest request) {

    PagedListHolder<UserDocument> fileList = null;  

    if( null == page ) {
        List<UserDocument> userDoc = userDocumentService.findImages();

        fileList = new PagedListHolder<UserDocument>();
        fileList.setSource(userDoc);
        fileList.setPageSize(10);
        request.getSession().setAttribute("fileList", fileList);

    } else if ("next".equals(page)) {
        // Return next set of list
        fileList = (PagedListHolder<UserDocument>) request.getSession().getAttribute("fileList");
        fileList.nextPage();

    } else if("prev".equals(page)) {
        // Return previous set of list
        fileList = (PagedListHolder<UserDocument>) request.getSession().getAttribute("fileList");
        fileList.previousPage();

    } else {
        // Return specific index set of list
        fileList = (PagedListHolder<UserDocument>) request.getSession().getAttribute("fileList");
        int pageNum = Integer.parseInt(page);
        fileList.setPage(pageNum);
    }

    ModelAndView mv = new ModelAndView("adminPageImageGallery");
    return  mv;
}

JSP:

<span style="float:left;">
                        <c:choose>
                            <c:when test="${pageListHolder.firstPage}">Prev</c:when>
                            <c:otherwise><a href="<c:url value='/show-gallery?page=prev'/>">Prev</a></c:otherwise>
                        </c:choose>
                    </span>
                    <span>
                        <c:forEach begin="0" end="${pageListHolder.pageCount-1}" varStatus="loop" var=p>
                        &nbsp;&nbsp;
                            <c:choose>
                                <c:when test="${loop.index == pageListHolder.page}">${loop.index+1}</c:when>
                                <c:otherwise><a href="<c:url value='/show-gallery?page=${loop.index}'/>">${loop.index}</a></c:otherwise>
                            </c:choose>
                        &nbsp;&nbsp;
                        </c:forEach>
                    </span>
                    <span>
                    <c:choose>
                        <c:when test="${pageListHolder.lastPage}">Next</c:when>
                        <c:otherwise><a href="<c:url value='/show-gallery?page=next'/>">Next</a></c:otherwise>
                    </c:choose>
                    </span>

和配置:

@Override
public void configureViewResolvers(ViewResolverRegistry registry) {

    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");
    registry.viewResolver(viewResolver);
}

感谢您的帮助和时间。

2 个答案:

答案 0 :(得分:0)

问题是您必须在jsp之前为这些请求参数值应用引号。这就是Spring无法将其识别为参数名称的原因。值。

boolean useUnlimitedHistory = SP.getString("unlimitedHistory", false);
String sql = "";
if (useUnlimitedHistory) {
    sql =  "SELECT * FROM " + HISTORY_NAME +
                " WHERE " + STATUS + " ORDER BY " + STATUS + " DESC " ;
} else {
    sql = "SELECT * FROM " + HISTORY_NAME +
                " WHERE " + STATUS + " ORDER BY " + STATUS + " DESC LIMIT " + historyNum ;
}

答案 1 :(得分:0)

请注意您的堆栈跟踪

org.apache.jasper.JasperException: /WEB-INF/views/adminPageImageGallery.jsp (line: 254, column: 88) quote symbol expected

问题可能是jsp中的var=p

<c:forEach begin="0" ... var=p>

将其替换为var =&#34; p&#34;,用引号括起来。