Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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
在屏幕上单击链接导出到csv文件时,获取jsp页面的源以及所需的数据_Jsp_Csv - Fatal编程技术网

在屏幕上单击链接导出到csv文件时,获取jsp页面的源以及所需的数据

在屏幕上单击链接导出到csv文件时,获取jsp页面的源以及所需的数据,jsp,csv,Jsp,Csv,当我尝试将数据导出到csv时,整个页面的html代码也会随数据一起出现 我尝试使用以下代码 Response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName.concat(extn) + "\""); response.setContentType("application/csv"); 在处理同一查询的过程中,您首先开始执行JSP以处理来自客户端浏览器的请求,然后在提交响应之前更改标题以声明内容类型为

当我尝试将数据导出到csv时,整个页面的html代码也会随数据一起出现

我尝试使用以下代码

Response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName.concat(extn) + "\"");
response.setContentType("application/csv");

在处理同一查询的过程中,您首先开始执行JSP以处理来自客户端浏览器的请求,然后在提交响应之前更改标题以声明内容类型为
application/csv
。但此时,JSP已经将输出写入响应,或者如果包含bean,JSP将在写入csv文件的内容后继续写入响应

在任何一种情况下,JSP的输出都将与csv混合

为了避免这种情况,您必须使用
Servlet
for,并将代码放入其
doGet
service
方法中,而无需经过JSP


但由于缺乏详细信息,我不确定这是否是实际问题。

我以前也遇到过类似的问题。我已通过将返回类型设置为null来修复该问题

原始代码(固定前)

公共字符串***(HttpSession会话、HttpServletRequest请求、HttpServletResponse响应){
**************************************
一些代码
**************************************
response.setContentType(“应用程序/csv”);
response.setHeader(“内容处置”、“附件;文件名=“+******.get***()+”.txt”);//将文件名设置为所需的名称。。
ServletOutputStream编写器=response.getOutputStream();
writer.print(“***”);
writer.print(“\t”);
writer.print(“****”);
writer.print(“\t”);
writer.println();
对于(inti=0;iThomas,
我也有同样的问题。我试过你给出的解决方案,但即使这样也不能解决这个问题。
在我使用JBoss服务器的本地开发环境中,它工作得很好,但是在我们使用weblogic服务器的prod env中,源代码会附加到文件中(只有csv和txt扩展名)。
我曾尝试使用OctetStream作为内容类型,甚至使用基于扩展的相应mime类型,但似乎没有任何效果


而且似乎响应已经有了源代码,我们在源代码之上添加了文件内容。

请添加相关信息……这段代码在哪里?在JSP本身中,在servlet中?这段代码在backing bea中,垃圾数据是我的JSP的源代码,我的下载链接在哪里,单击后调用backing bean函数,其中我的代码正在编写抱歉,但我的水晶球目前功能不正常:-(,信息太少,我无法想象会发生什么。response.setContentType(“application/vnd.ms excel”);response.setHeader(“Content disposition”,“attachment;filename=“+filename.concat(extn));试试看{cachedRowData=consumerdao.exportempuntstoexcel(strHiddenBtchEndDate);log.debug(“size”+cachedRowData.size());PrintWriter out=response.getWriter();/*ServletOutputStream out1=response.getOutputStream();*/*ZipOutputStream output=new ZipOutputStream(out1);output.putnentry(new ZipEntry(fileName.concat(.csv)));*/ResultSetMetaData/***您能告诉我您的电子邮件ID吗?我的页面上有一个下载链接,通过它可以点击支持bean并执行其方法。response.setHeader(“内容处置”,“附件;文件名=“+filename”);fistrm=new FileInputStream(路径+文件.分隔符+分支代码+文件.分隔符+文件名);bout=new BufferedOutputStream(response.getOutputStream())而((bytesRead=fistrm.read(buffer))>-1{bout.write(buffer,0,bytesRead);bytesbuffer+=bytesRead;if(bytesbuffer>1048576){bytesbuffer=0;bout.flush();}解决了这个问题,我返回了null而不是jsp页面,但不确定在jboss上运行applucation时它是如何工作的
    public String ***( HttpSession session,HttpServletRequest request, HttpServletResponse response) {


**************************************
some code

**************************************

            response.setContentType("application/csv");   
            response.setHeader("content-disposition","attachment;filename="+****.get****()+".txt"); // set the file name to whatever required..
            ServletOutputStream  writer = response.getOutputStream();   

            writer.print("***");
            writer.print("\t");
            writer.print("****");
            writer.print("\t");
            writer.println();


        for(int i=0;i<***.get****().size();i++){

            writer.print(""+***.get****().get(i).get***());

**********************************
somecode
*********************


        return "jsp name";

    }