Tatarao voleti
Tatarao voleti

Reputation: 513

How to write JSP Expression Tag in Scriptlet

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

Answers (3)

LMK
LMK

Reputation: 2962

You can use EL Expressions ${}

Upvotes: 0

AllTooSir
AllTooSir

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

TwilightTitus
TwilightTitus

Reputation: 296

Yes you can use the "report" variable.

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

Upvotes: 1

Related Questions