• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

displaying jsp filename to downloading file in internet explorer

 
grk kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i am using the following code to download file from server.


<%
File file = new File("/ed63/ora510/eld611i2comn/html/eisrs/data/backuploadbalance.xlsx");
String resultXLS="excelfileName1441.xlsx";
response.setHeader("Content-Length", ""+file.length());
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8");
response.setHeader("content-disposition", "attachement; filename=\"" + resultXLS + "\"");
response.setHeader("Content-Transfer-Encoding", "binary");

FileInputStream fileIn = new FileInputStream(file);
OutputStream outExcel = response.getOutputStream();

byte[] outputByte = new byte[8192];
//copy binary contect to output stream
while(fileIn.read(outputByte, 0, 8192) != -1)
{
outExcel.write(outputByte, 0, 8192);
}

fileIn.close();
outExcel.flush();
outExcel.close();

%>


when i open in firefox the file name shows as "excelfileName1441.xlsx";
in internet explorer the file name shows as jsp file name.



how to display the file name in internet explorer.

Thanks & regards

kumar

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doing this in a JSP is folly. The first step is to refactor this code into a servlet. Please post back when that is accomplished.
 
grk kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

Thanks for your answer.

i converted to servlet.

code:




import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class down
*/
@WebServlet("/down")
public class down extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public down() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
File file = new File("d:\\Client Versions.xlsx");
setResponseHeader(response, "DisplayHideTabs.xlsx",file);
FileInputStream fileIn = new FileInputStream(file);
OutputStream outExcel = response.getOutputStream();

byte[] outputByte = new byte[8192];
//copy binary contect to output stream
while(fileIn.read(outputByte, 0, 8192) != -1)
{
outExcel.write(outputByte, 0, 8192);
}

fileIn.close();
outExcel.flush();
outExcel.close();

}
private void setResponseHeader(HttpServletResponse response, String resultXLS,File file)
{
response.setHeader("Content-Length", ""+file.length());
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8");
response.setHeader("content-disposition", "attachement; filename=resultXLS.xlsx");
response.setHeader("Content-Transfer-Encoding", "binary");


}

}


i am still facing the problem.

code works fine in firefox.

when it comes to the internet explorer. it displays the filename as jspname when i click open.

i think problem is with response header.

thanks & regards


Kumar
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code to the forums.

grk kumar wrote:
when it comes to the internet explorer. it displays the filename as jspname when i click open.


As there is no longer a JSP, what is "jspname"?
 
grk kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

Thanks for your suggestion.

here it will displays servlet name when i click open in internet explorer.

it is working fine in firefox.

i am using tomcat server in this case.



Thanks & regards

Kumar

error.JPG
[Thumbnail for error.JPG]
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing that perhaps you mean that part of the requesting URL is being used by IE? It isn't very helpful when you use imprecise phrases like "servlet name". Maybe you could give an example if you don't know the names of things?
 
grk kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

the problem is with Internet explorer.

the code works fine chrome and firefox for both 2003 and 2007 format.

when it comes to the internet explorer some thing is missing.

i think i need to set some response header for internet explorer.

any suggestions.

Thanks & regards

Kumar
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I'm guessing that perhaps you mean that part of the requesting URL is being used by IE? It isn't very helpful when you use imprecise phrases like "servlet name". Maybe you could give an example if you don't know the names of things?


That WAS a suggestion.
 
grk kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

Thanks for your response.

internet explorer using my servlet name as file name.



in this case the file name displays as down.xlsx

can you please give solution for this.


 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I would suggest you should spell "attachment" correctly. And I would suggest you specify a filename if you are concerned about the filename the browser is going to use. Which it seems you are, since you are complaining about the browser's choice.

As for "down.xslx", that seems like a strange choice for the name of your servlet. Was that really what you meant?
 
grk kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

thanks for your response.

i need to force the browser to open the file as given file name.

here the files are changed based on client request.


there are links in jsp page having all filenames.

when user clicks on link the corresponding file downloaded.




this is my requirement.

Thanks & regards

Kumar






 
grk kumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

thanks for your response.


excel contains pivot table.

if i use setHeader as


data lost occurred in excel file.

so i must use "inline" in place of "attachment".

thanks & regards

kumar.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic