0

有人可以帮帮我吗?我正在使用 JQuery $.getJSON() 根据选定的下拉列表(类别)加载一个下拉列表(子类别)的内容。

由于某种原因,我收到了 IllegalStateException。提前谢谢你。

<script>
    $(document)
            .ready(
                    function() {

                        // reload subcategories when changing category
                        $('#categories').change(loadSubcategories);

                    });

    // load the subcategories based on selected category
    function loadSubcategories() {
        $.getJSON('findSubcategoriesForCategory.html', {
            categoryId : $('#categories').val(),
            ajax : 'true'
        }, function(data) {
            var html = '<option value="">Select Subcategory</option>';
            var len = data.length;
            for ( var i = 0; i < len; i++) {
                html += '<option value="' + data[i].id + '">' + data[i].name
                        + '</option>';
            }
            html += '</option>';

            $('#subcategories').html(html);

        });
    }
</script>

这是控制器方法的代码:

@RequestMapping(value = "findSubcategoriesForCategory", method = RequestMethod.GET)
public @ResponseBody
List<Subcategory> findSubcategoriesForCategory(
        @RequestParam(value = "categoryId", required = true) String categoryId) {

    List<Subcategory> returnList = new ArrayList<Subcategory>();

    try {
        returnList = categoryService
                .findSubcategoriesForCategory(categoryId);
    } catch (Exception e) {
        LOGGER.error("An Error occured when Finding sub-categories for category id: " + categoryId);
    }

    return returnList;

}

java.lang.IllegalStateException: getOutputStream() 已经在 org.apache.catalina.connector.Response.getWriter(Response.java:611) at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade. java:198) 在 javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112) 在 org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125) 在 org.apache.jasper.runtime.JspWriterImpl.flushBuffer (JspWriterImpl.java:118) at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:273) at java.io.PrintWriter.write(Unknown Source) at org.apache.jasper.runtime.JspWriterImpl.flushBuffer (JspWriterImpl.java:119) 在 org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:326) 在 org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:342) 在 org.apache.jsp.WEB_002dINF.jsp.include.header_jsp._jspx_meth_c_005fforEach_005f1(header_jsp.java:341) 在 org.apache.jsp.WEB_002dINF.jsp.include.header_jsp._jspx_meth_c_005fforEach_005f0(header_jsp.java)在 org.apache.jsp.WEB_002dINF.jsp.include.header_jsp._jspService(header_jsp.java:133) 在 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 在 javax.servlet.http.HttpServlet .service(HttpServlet.java:717) 在 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) 在 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) 在 org. org.apache.catalina.core.ApplicationFilterChain 上的 javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 上的 apache.jasper.servlet.JspServlet.service(JspServlet.java:260)。internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646) at org.apache .catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551) 在 org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488) 在 org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java :968) 在 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 在 javax.servlet.http 的 org.apache.jsp.WEB_002dINF.jsp.errorMsg_jsp._jspService(errorMsg_jsp.java:69)。 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) 中的 org.apache.jasper 中的 HttpServlet.service(HttpServlet.java:717)。servlet.JspServlet.serviceJspFile(JspServlet.java:313) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org .apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher .java:646)在 org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551) 在 org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488) 在 org.springframework.web。 org.springframework.web.servlet.view.AbstractView 上的 servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:229)。在 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817) 在 org.springframework.render(DispatcherServlet.java:1047) 在 org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047) 渲染(AbstractView.java:250) .web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) 在 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:669) 在 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java :574) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:617) 在 javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( ApplicationFilterChain.java:290) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core .StandardContextValve.invoke(StandardContextValve.java:191) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 在 org.apache。catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol. java:602) 在 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 在 java.lang.Thread.run(Unknown Source)

4

2 回答 2

1

这是来自您的网络服务器的响应。前端不涉及 Java。:)

于 2012-06-06T13:48:09.170 回答
0

我必须在我的 Hibernate 映射 getter 方法中添加这个 @JsonIgnore 才能使代码正常工作。

于 2012-06-06T14:51:51.130 回答