1

How to write expression tag inside the Scriptlet in JSP. I want to export data to Excel sheet. I wrote the fallowing statement to JSP

<% response.addHeader("Content-Disposition","attachment;filename=title.xls"); %>

here i m writing exported file name as 'title', here i want to change file name. so i write like

<% String report=label.getLable('rep'); %>

How can i use 'report' variable in JSP Scrptlet ?

Thanks

Tatarao voleti
  • 513
  • 3
  • 7
  • 23
  • 2
    Don't use scriptlets. Use the JSP EL. Modifying the response headers and sending An Excel file should be done by a servlet, not by a JSP. – JB Nizet Jul 26 '13 at 07:05

3 Answers3

1

Yes you can use the "report" variable.

<% String report=label.getLable('rep'); %>
<% response.addHeader("Content-Disposition","attachment;filename=" + report); %>
TwilightTitus
  • 190
  • 1
  • 9
1

You can use a bit of JSTL and EL :

<c:set var="title" scope="request" value="<%=label.getLable('rep')%>"/>
<% response.addHeader("Content-Disposition","attachment;filename=${title}.xls"); %>

Also read , How to avoid Java Code in JSP-Files?

Moreover , you can have a Servlet do this kind of job , not JSP.

The use of scriptlet is not advisable at all :

<% String report=label.getLable('rep') + ".xls"; 
   response.addHeader("Content-Disposition","attachment;filename=" + report); %>
Community
  • 1
  • 1
AllTooSir
  • 48,828
  • 16
  • 130
  • 164
  • Thanks brother... I used JSTL and EL but.. file name comes as {title}.xls on download dialogue box. I used second method above but filaname doesn't take full string (ex: filaname=something by simeone.xls). it only takes 'something' and extension is not coming, so it shows unsupported file format... – Tatarao voleti Jul 26 '13 at 09:26
0

You can use EL Expressions ${}

LMK
  • 2,882
  • 5
  • 28
  • 52