Hi there,

I am a complete newbie to JSP so apologies if this is a blindingly obvious question - I have researched on Google, but can't get this working.

I have a simple switch statement as below:

<%
for (int a=0; a<10; a++) {			
  if ( null != countryID[a] ) {
        
  int country = countryID[a];
        
     switch(country) {
  
     case 8:
     out.println("Case 8");
     break;
 
     case 13:
     out.println("Case 13");
     break;

     default:
     out.println("Default case");
     }
   }
}

	%>

If I set the country integer manually (e.g. int country = 18;) the statement works fine, however If I try to grab the integer from countryID[a] (which is necessary to make the switch dynamic) then it doesn't work.

I'd be most grateful for any advice.

It might help to know exactly what "doesn't work" means. In any case, do not use scriptlets.

Hey masijade - sorry for being vague, I just get a blank screen with the above code, there are no error messages.

If I plugin a number manually e.g:

int country = 8;

The page loads and the switch statement works.

Based on your advice not to use scripltets I'm assuming there's a better way to do this however I'm completely new to jsp and our website is due to be replaced in the next few months so I was trying to put together a quick fix in the meantime.

Cheers.

Check the logs. There is an error somewhere.

As far as not using scriptlets, all I can say is to read the tutorials (the JEE tutorials, of course).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.