Reputation: 513
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
Upvotes: 1
Views: 2313
Reputation: 49432
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); %>
Upvotes: 1
Reputation: 296
Yes you can use the "report" variable.
<% String report=label.getLable('rep'); %>
<% response.addHeader("Content-Disposition","attachment;filename=" + report); %>
Upvotes: 1