Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generating xls in servlet giving error

 
nitin singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have follwoing code in servlet/action class.
BinaryView docBinaryView =(BinaryView)documentInstance1.getView(OutputFormatType.XLS);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Type", "application/vnd.ms-excel");
response.setDateHeader("expires", 0);
docBinaryView.getContent(response.getOutputStream());
return mapping.findForward(null);

On click of a button I forward control to this servelet and a xls should get generated.
I get an alert message
could not open http://localhost:9080:/tilesPocxls.do
then after that
Microsoft xl cannot access http://localhost:9080:/tilesPocxls.do.There may be several reasons.

Same code I am using for generation of pdf .it works..
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I done a google search on "BinaryView" class. It seems like your are using business object(BO)'s report engine Java library. If so,My wild guess,


Try changing this



to

 
nitin singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
correct this is for Business objects.But it doesnt recognises excel.

Same code for pdfformat works fine but givees error for excel format.I have struts application caling this through action classs
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked with API documentation for class OutputFormatType and there is no constant variable called OutputFormatType.XLS but it has OutputFormatType.EXCEL


URL which I read.
 
nitin singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats True prabhu I too saw that link.But actually the implementation is xls only as when I say OutputFormatType. there is no EXCEL but xls.

The problem is If i open this in a new window I only get that error but if i try to open this excel in parent.I get same error dialog box but latter the excel opens.
So I see problem some where else.
 
nitin singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prabhu same code I use for pdf generation just chnage the content type to pdf and it runs fine ..
I really wonder how the say EXCEL in the documentaion actually its exl.

Regards,
Nitin
 
subramanian thiruppathi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh..
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Otherthan what I said above, It seems like there is no issue with your code. However, here is working code which return XLS to client.



It may be possible that client having issue in opening XLS. Here is some trouble shooting steps I know :

1. Conform the XLS file you are passing it to client is opening without any error by double click the file.
 
nitin singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem got thanks..
The change which I did was I moved this code to a servlet.And calling that servelet from my jsp.Something to do with API I guess.


public class Test extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
System.out.println("Welcome to test servlet");
HttpSession session = request.getSession();
String storageToken = (String) session.getAttribute("storageTokenXLPdf");
ReportEngine webiRepEngine = (ReportEngine) session.getAttribute("ReportEngine");
DocumentInstance documentInstance1 = webiRepEngine
.getDocumentFromStorageToken(storageToken);
Report report = documentInstance1.getReports().getItem(0);
ImageOption imageOption = documentInstance1.getImageOption();
imageOption.setImageCallback("getImage.jsp");
imageOption.setImageNameHolder("image");
imageOption.setStorageTokenHolder("storageToken");
BinaryView docBinaryView = (BinaryView) documentInstance1
.getView(OutputFormatType.XLS);

//response.reset();
//response.flushBuffer();
//response.isCommitted();
//response.getWriter();
System.out.println("commited "+response.isCommitted());
//response.resetBuffer();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Type", "application/vnd.ms-excel");
response.setDateHeader("expires", 0);
docBinaryView.getContent(response.getOutputStream());
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic