Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringWebFlow流媒体_Java_Spring_Spring Mvc_Tomcat_Spring Webflow - Fatal编程技术网

Java SpringWebFlow流媒体

Java SpringWebFlow流媒体,java,spring,spring-mvc,tomcat,spring-webflow,Java,Spring,Spring Mvc,Tomcat,Spring Webflow,我在SpringWebFlow/JSF应用程序中执行流操作()时遇到问题。我已经看到一些人使用MVC控制器来解决这个问题,但我想使用它如下 我使用的是Tomcat 7.01、Spring WebFlow 2.3.1和Primefaces 4.0 问题是,当我想下载一个文件时,什么都没有发生。代码被执行,但在浏览器中什么也没发生。有人知道可能是什么问题吗,可能是xml中的其他设置 非常感谢 我的行为看起来像: @Component public class PrintCSVAction exten

我在SpringWebFlow/JSF应用程序中执行流操作()时遇到问题。我已经看到一些人使用MVC控制器来解决这个问题,但我想使用它如下

我使用的是Tomcat 7.01、Spring WebFlow 2.3.1和Primefaces 4.0

问题是,当我想下载一个文件时,什么都没有发生。代码被执行,但在浏览器中什么也没发生。有人知道可能是什么问题吗,可能是xml中的其他设置

非常感谢

我的行为看起来像:

@Component
public class PrintCSVAction extends AbstractAction {
private static final String CSV_FILENAME = "export.csv";

public Event doExecute(RequestContext context) throws IOException {
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getNativeResponse();

        response.setHeader("Content-Disposition", "attachment; filename=\"" + CSV_FILENAME + "\"");
        OutputStream out = response.getOutputStream();
        response.setContentType("text/csv; charset=UTF-8");
        out.write(new String("blablablab\n").getBytes("utf-8"));
        out.flush();
        out.close();

        context.getExternalContext().recordResponseComplete();
        return success();
    }
}
<view-state id="search" view="export.xhtml">
    <transition on="home" to="finish" />
    <transition on="printCSV">
        <evaluate expression="printCSVAction" />
    </transition>
</view-state>
视图状态中的转换定义如下所示:

@Component
public class PrintCSVAction extends AbstractAction {
private static final String CSV_FILENAME = "export.csv";

public Event doExecute(RequestContext context) throws IOException {
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getNativeResponse();

        response.setHeader("Content-Disposition", "attachment; filename=\"" + CSV_FILENAME + "\"");
        OutputStream out = response.getOutputStream();
        response.setContentType("text/csv; charset=UTF-8");
        out.write(new String("blablablab\n").getBytes("utf-8"));
        out.flush();
        out.close();

        context.getExternalContext().recordResponseComplete();
        return success();
    }
}
<view-state id="search" view="export.xhtml">
    <transition on="home" to="finish" />
    <transition on="printCSV">
        <evaluate expression="printCSVAction" />
    </transition>
</view-state>

问题是p:commandLink默认使用ajax。要以非ajax方式提交表单,我们必须包含ajax=“false”或使用其他元素(例如,h:commandButton)


现在可以了

<p:commandLink action="printCSV" ajax="false">
    <p:graphicImage value="/css/images/csv.png" />
</p:commandLink>