Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

output

 
Bala samy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<% x=10; %>
<% int x=5; %>
<%! int x; %>
x= <%=x%>
x= <%=page.x%>
 
Siddharth Purandare
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
output it is upto container, how it translate JSP to Servlet?

For Example, Servlet may look like this,



So, result is not justifiable.
 
Bala samy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


No type ? This will give a compilation error !
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nooooooo Celinio Fernandes ,


please try the code
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In any language the will works fine.
 
Rohitt Vermaa
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic