wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "output" Watch "output" New topic
Author

output

Bala samy
Greenhorn

Joined: Sep 20, 2006
Posts: 4
<% x=10; %>
<% int x=5; %>
<%! int x; %>
x= <%=x%>
x= <%=page.x%>
Siddharth Purandare
Ranch Hand

Joined: Nov 13, 2006
Posts: 101
I tried to Run your code. It gives the compilation error. But I got the solution by trying some other way.

What you are expecting you will get by the below code because implicit variable page is of class java.lang.Object and it refers to the instance of generated class.




It will print

x=5 x=5


Siddharth Purandare<br />SCJP 1.4 - 76%<br />SCWCD 1.4 - 85%<br /> <br />It is the "attitude" and not the "aptitude" which determines "altitude".
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

output it is upto container, how it translate JSP to Servlet?

For Example, Servlet may look like this,



So, result is not justifiable.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Bala samy
Greenhorn

Joined: Sep 20, 2006
Posts: 4
Thank you
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
Prabhu Venkatachalam, You are wrong

try this

<% x=10; %>
<% int x=5; %>
<%! int x; %>
x= <%=x%>
x= <%= this.x%>


the output is

x=5 x=10

the code will convert to like this



SCJP 5.0<br />SCWCD 1.4<br />Preparing for <b>SCEA</b>.<br /><b>"I prefer an interesting vice to a virtue that bores."</b>
Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547



No type ? This will give a compilation error !


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCBCD 5
Visit my blog
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
Nooooooo Celinio Fernandes ,


please try the code
Sayak Banerjee
Ranch Hand

Joined: Nov 28, 2006
Posts: 292

It won't produce an error because the type is mentioned before it's used

Check the generated servlet Celinio
[ December 14, 2006: Message edited by: Sayak Banerjee ]

Turn on, tune in, drop out.
Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547

indeed, my mistake.
It is confusing, I know several languages, some allow use of a variable before the line where it is declared and some do not ...
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
In any language the will works fine.
Rohitt Vermaa
Ranch Hand

Joined: Oct 12, 2006
Posts: 232
Hi, I found this question in one of the exam simulator where the answer is given as compilation error as page is an object, there is no variable in object as x. So page.x won't compile.


SCJP ,SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: output