Link to home
Start Free TrialLog in
Avatar of nediam1234
nediam1234

asked on

Problem creating servlet as a subclass!

I just created a java class that creates an excel document.
It has a function called saveToFile which saves the excel document to a file.

Now I also want to be able to "download" the document just created, I know I could create another class (a servlet) setting the content type to "application/vnd.ms-excel" and then download the file... But! I would like to do this in a single file (not create another file for the servlet), so I thought about creating a servlet subclass. But then I don't know how I can call the subclass from the other class.    Any idea how I can achieve my goal (either by servlet subclass or anything else....) ??

Am I explaining my problem well enough?  
 
thanks
Avatar of shinobun
shinobun

Subclassing will also introduce a new class.  Why not just create a new Servlet class?  I think that would be more maintainable.
Avatar of nediam1234

ASKER

thanks for a quick reply,

When I save my excel sheet to a file I use something like:

ExcelSheet sheet = new ExcelSheet();
sheet.someFunctionToCreateTheDocument();
sheet.someAnotherFunctionToCreateMoreOfTheDocument();

Then, I can call
sheet.saveToFile("myFilename.xls");
to save the file.

It would be nice to be able to call something like this in the jsp page:
response.sendRedirect(sheet.downloadServlet);
to "download" the document. Without having to pass the whole document as a parameter to another servlet (the variable "sheet" in the above sample already has the whole excel document in an variable).

are you saying that I should call something like this?  :
ExcelSheet sheet = new ExcelSheet();
sheet.someFunctionToCreateTheDocument();
sheet.someAnotherFunctionToCreateMoreOfTheDocument();

location.href= 'newServletFromANewFile?theData=<%=sheet.getTheWholeDocumentAsString()%>';

then my question is... isn't it a problem calling a servlet if the excel sheet is be big?
ASKER CERTIFIED SOLUTION
Avatar of shinobun
shinobun

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial