Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JSP Scriplet doubt

 
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the two is correct syntax

A <% if(true)%>
I am fine
<%else%>
You are fine

B<%! int i; %>
<% if(i==0) %>
<% i++; %>
<% else %>
<%= "i==1" %>

Kindly help.
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I think the newline after if give you problem. Safer side use {} brackets for the if.

Thanks
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's right...

But these were the options given in the mock.
I am aware of the fact that newline can create problem in such scenerio.

Could you please give the correct answer from these two options.
 
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry, Sandeep, but these two JSP chunks are very poor examples and a cert question written like this would be dropped.

Here is the code generated by Tomcat v5.0.24 for the first item:


As you can see this is invalid Java code.

You can safely ignore bad mock questions such as this. You will not see anything this poorly concieved on the real exam.

Cheers,
Bryan
 
Bryan Basham
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, I just read your question again. The answer is both of these JSP code chunks are valid JSP syntax. Unfortunately, they are translated into invalid Java syntax. Does that answer your question?

-Bryan
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bryan,

I am sure we won't face such questions in the actual exam, but incase if encounter one, is it fine to go the by syntax and select the answer true ?

Thanks,
Reshma
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's right...

Atleast the syntax for both of these code is correct.
so in case we get such question in exam, I think we should go for both of them.

Thanks Bryan
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic