All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: About Question enthuware.jwpv6.2.1043 :
PostPosted: Mon Aug 15, 2011 1:08 am 
Hi,

Scriptlet #1:

//1 <% int i = 10; %>
//2 System.out.println("starting loop");
//3 <%for(i=0; i< 10; i++) { out.println(i); } %>

Line 2 is not inside <% ... %>


Top
  
 
 Post subject: Re: About Question enthuware.jwpv6.2.1043 :
PostPosted: Mon Aug 15, 2011 10:52 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6799
The given explanation contains the following:
Quote:
Although System.out.println("starting loop"); is not HTML but if you don't put it inside <% %>, it will be considered as HTML. It won't cause any compile or runtime problems as the JSP parser will not even look at it. This line will be output as is to the browser. So 1 is valid.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.1043 :
PostPosted: Tue Jun 28, 2016 4:43 pm 
Offline

Joined: Fri Oct 09, 2015 3:52 am
Posts: 9
Okay, but the question says "Which of the following are correct JSP scriptlet?", and the "System.out.println("starting loop");" occurs outside of the scriptlet tags, so technically it's not a scriptlet. At least, that was my thinking.

Should I interpret this question to say "Which of the following will compile and run?" or is there a clearer definition of scriptlet that I need to know?


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.1043 :
PostPosted: Tue Jun 28, 2016 7:42 pm 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6799
No, the whole thing is a valid scriptlet even if some part of it may not be so individually.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.1043 :
PostPosted: Thu Nov 02, 2017 1:36 am 
Offline

Joined: Thu Nov 02, 2017 1:33 am
Posts: 4
Why option 3 is wrong:
3. <% int i = 0, s = 0; System.out.println("starting loop"); for(; i< 10; i++) { s+=i; } %>

AS far as i know for(;i<10;i++) will not create any new variable. It will use the already declared one.
I think Explanation is not correct.

_jspService(...) {    ...    int i = 0;    System.out.println("starting loop");    for(int i=0; i< 10; i++) { out.println(i); } // here i is being declared again, so it will not compile.    ... }

Please help me here.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.1043 :
PostPosted: Thu Nov 02, 2017 2:06 am 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6799
Did you try executing the given code?


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.1043 :
PostPosted: Thu Nov 02, 2017 6:45 am 
Offline

Joined: Thu Nov 02, 2017 1:33 am
Posts: 4
Yes infact I did.
Here is the jsp I had

<%@ page import="java.util.*" %>

<html>
<body>
<h1 align="center">Beer Recommendation JSP </h1>

<h2 align ="center"> Check the Loop: </h2>
<% int k = 0, s=0;
out.println("starting loop");
for(; k< 10; k++)
{
out.println("In the loop");
s+=k; }%>


</body>
</html>

And the output I got is :

Beer Recommendation JSP

Check the Loop:

starting loop In the loop In the loop In the loop In the loop In the loop In the loop In the loop In the loop In the loop In the loop.


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.1043 :
PostPosted: Thu Nov 02, 2017 11:16 pm 
Offline
Site Admin

Joined: Fri Sep 10, 2010 9:26 pm
Posts: 6799
Very sorry, I misunderstood your question. Yes, scriptlet 3 is correct and the option that is marked as correct i.e. option 5 indeed says scriptlet 1, 3, and 4 are valid scriptlets.

Option 3 is invalid because it says scriptlets 3 and 4 are valid. It does not list scriptlet 1 as valid.

Since you have to select only 1 option, you need to select the best option, which is option 5.

(The explanation explains why scriptlet 2 is not valid.)


Top
 Profile Send private message  
 
 Post subject: Re: About Question enthuware.jwpv6.2.1043 :
PostPosted: Fri Nov 03, 2017 1:10 am 
Offline

Joined: Thu Nov 02, 2017 1:33 am
Posts: 4
Got it..
Thanks..


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Template made by DEVPPL/ThatBigForum