Silviu
Silviu

Reputation: 175

Calling a method from servlet in a JSP page,method with parameters from that JSP page

I tried different ways to call that method, but none worked. My problem is that I want to give as variable parameters from that jsp page where I calling that method

those are my varabiles:

<c:forEach begin="0" end="21" step="1" var="time">
<c:forEach begin="${0}" end="${6}" step="1" var="day">
.............
</c:forEach>
.........................
</c:forEach>
<c:set var="sala" value='<%=session.getAttribute("room").toString()%>'/>
<c:set var="z" value='<%=Integer.parseInt(session.getAttribute("next").toString())%>'/>

Here I tried to call my method

<c:set var="getData"   value='<%= try{
    mysql a =new mysql();
    a.getData( %>${time},${day}<%+%>${z},${sala}<%);

}catch (Exception ex){  return ex.toString();}  %>'/>

Upvotes: 0

Views: 82

Answers (1)

Madhuri
Madhuri

Reputation: 126

we can't use the jstl variables directly in scriptlet tags.

We need to use the below syntax :

         pageContext.getAttribute(String name); 

According to your example,

<%
try
{
mysql a =new mysql();
String time=pageContext.getAttribute("time"); 
String day=pageContext.getAttribute("day"); 
String sala=pageContext.getAttribute("sala"); 

 String getData=a.getData(time,day,sala);
 }
catch (Exception ex){  return ex.toString();}  
pageContext.setAttribute("getData", getData);
%>
<c:out value="${getData}"/>

Upvotes: 1

Related Questions