Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

How do I make a variable available to many scriptlets in a JSP?

How do I make a variable available to many scriptlets in a JSP?

i.e., I have a string obtained from a session object and would like to convert it into an integer to be used in several scriptlets in  my JSP.

The following does not work:

I would like to use int MAX_NUM in the scriptlets, when MAX_NUM has the value obtained from session object numActiveSDPsDiag.

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head><title>JSP Page</title></head>
<body>

<table align="center" width="70%" border="0" background="blue_marble.gif">
<tr>
<td align="center"><font color="gold" size=6><br>SERVICE DELIVERY POINT RANKING </font><br><br></td>
</tr>
</table>

<table align="center" width="70%" border="0" background="blue_rock.gif">
<tr>
<td align="left">
<b> Service Delivery Point Ranking in Number of Diagnosises made: </b><br>

<% String theLimit = (String) session.getAttribute("numActiveSDPsDiag"); %>

<%! int MAX_NUM = Integer.parseInt(theLimit); %>
   
<%
String[] sdpNames = (String[]) session.getAttribute("sdpNames");
String[] numOccurancesDiag = (String[]) session.getAttribute("numOccurancesDiag");
for (int i = 0; i< MAX_NUM; i++) {
     String name = sdpNames[i];
     String occurance = numOccurancesDiag[i];
%>
</tr>
<tr>
  <td align="left" valign="top"><%= name %> </td>
  <td align="left" valign="top"><%= occurance %></td>
</tr>
<%
}
%>
<br>

<tr>
<td align="left"> <b> Service Delivery Point Ranking in Number of Patient Visits made: </b><br>
<%
String[] visitedSDP = (String[]) session.getAttribute("visitedSDP");
String[] occuranceOfVisits = (String[]) session.getAttribute("occuranceOfVisits");
for (int i = 0; i< MAX_NUM; i++) {
     String sdp = visitedSDP[i];
     String occurance = occuranceOfVisits[i];
%>
<tr>
  <td align="left" valign="top"><%= sdp %> </td>
  <td align="left" valign="top"><%= occurance %></td>
</tr>
<%  
}
%>
<br>
</td>
</table>

</body>
</html>

I do appreciate your kind instruction
0
Rrugemalira
Asked:
Rrugemalira
  • 2
2 Solutions
 
ManishLeadCommented:
<% String theLimit = (String) session.getAttribute("numActiveSDPsDiag");

 int MAX_NUM = Integer.parseInt(theLimit);
%>
karan
0
 
sujata7576Commented:
<%
int MAX_NUM  = 0;
String theLimit = (String) session.getAttribute("numActiveSDPsDiag");
if(theLimit != null)
   MAX_NUM  = Integer.parseInt(theLimit);
%>
0
 
ManishLeadCommented:
Thank you for points..! :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now