导出为 pdf,excel,xml 使用 displayTag 和 spring 不工作

export to pdf,excel,xml using displayTag with spring not working

我在 jsp 中使用显示标签,但它不起作用。我正在为后端使用 spring MVC 框架。 可能 jsp 无法识别显示标签。我已经包含了 spring 和显示标签所需的所有罐子。

我的jsp代码:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>

</head>

<body>

    <div>
        <c:if test="${not empty recordList}">
        <display:table id="txt" pagesize="10" requestURI="" name="recordList">
            <display:column property="trafficType"></display:column>
            <display:column property="publisherId"></display:column>
            <display:column property="publisherName"></display:column>
            <display:column property="publisherGroupDevice"></display:column>
            <display:column property="clicks"></display:column>
            <display:column property="cost"></display:column>
            <display:column property="merchantSales"></display:column>
        </display:table>
        </c:if>
    </div>

</body>

</html>

我的控制器包括这一行

model.addAttribute("recordList", recordList);

我在控制台上收到此错误

    INFO  aytag.export.ExportViewFactory - Initializing ExportViewFactory with type={csv,excel,xml,pdf}
2016-05-19 22:35:55,660 [http-bio-8080-exec-2] INFO  tag.properties.TableProperties - No LocaleResolver configured.
2016-05-19 22:35:55,698 [http-bio-8080-exec-2] INFO  tag.properties.TableProperties - I18nResourceProvider initialized to org.displaytag.localization.I18nJstlAdapter.
2016-05-19 22:35:55,891 [http-bio-8080-exec-2] ERROR                 nextagBase.jsp - forwarding to URL (iDChnl == null): /serv/main/serv/main/internal/v1/generateReport failed.
java.lang.IllegalStateException: Cannot forward after response has been committed
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:348)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
    at nextag.api.Jsp.forward(Jsp.java:4472)

如此处所述java.lang.IllegalStateException: Cannot forward / sendRedirect after response has been committed 可能是由于在 sendRedirect(); 之后调用 forward(); 这可能是无意中完成的,如果您有:

protected void doPost() {
    if (someCondition) {
        sendRedirect();
    }
    forward(); // This is STILL invoked when someCondition is true!
}

forward 方法将在 sendRedirect 之后调用,即使条件为真

很抱歉我发布了这个问题;但经过大量调试后,我发现显示标签没有从控制器获取正确的列表数据结构是我的错误,所以我更正了它并完美地编码 运行。