cancel
Showing results for 
Search instead for 
Did you mean: 

How to give default as empty to save as filename

Former Member
0 Kudos

Hi all,

I need to open a excel file on the browser.User has to enter his own filename for Save As-> Filename.

It is opening successfully.

while trying to Save As (file->Save As) for filename it is giving like this "quotes.csv?s=%5EIXIC&f=sl1d1t1c1ohgv&e=.xls"

but I have to give(default) empty space for filename (after opening the excel on the browser tyring to Save As filename)

this is the problem to give empty space(default) for filename for Save AS.

My code is in struts action

<b>

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

throws Exception {

// getting data from JSP

String columns = request.getParameter("columns");

String searchString = request.getParameter("searchstring");

String srchType = request.getParameter("searchType");

System.out.println(" Action columns: "+columns);

System.out.println("Action searchString: "+searchString);

System.out.println("Action srchType: "+srchType);

String filename = null;

try {

//getting servlet context for absolute path

ServletContext context = getServlet().getServletContext();

//creating object for dao

RegistrationMigrationDAO dao = new RegistrationMigrationDAO();

//getting file path from dao

filename = dao.migrateregistration(columns, searchString, srchType,

request, context, getServlet().getServletName());

//System.out.println("url in action: " + filename);

//setting mime type

response.setContentType("application/vnd.ms-excel");

//setting the header

//response.setHeader("Content-Disposition", "attachment; filename="+ filename);

//creating fileinputstream object to open the file

FileInputStream fis = new FileInputStream(filename);

//passing FIS object to work book to open in the form of spread sheet

HSSFWorkbook book = new HSSFWorkbook(fis);

//creating object for outputstream to disply

OutputStream out = response.getOutputStream();

book.write(out);

//closing the outputstream

out.close();

} catch (Exception e) {

e.printStackTrace();

}

return null;

}

</b>

by using this

<b>//response.setHeader("Content-Disposition", "attachment; filename="+ filename);</b>

I am getting but excel is not opening on the browser separately excel file opening (not on the browser separate window as excel). I want open excel on same window(browser) and for Save As-> Filename as empty.

this is the thing I have to do.

Give me solution to give saveas filename as empty after opening the excel on the browser.

<b>User has to enter his own filename it is allowing but I ahve to give filename default as empty space.</b>

Thanks in advance

Rama Krishna

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

try

response.setHeader("Content-Disposition", "inline; filename="+ filename);

This should force your browser to open the file in the same window.

And I had the problem with empty file name in save as, too. For our purposes, it helped to shorten the filename. But as I was told this depends on IE and OS versions.

Regards, Astrid