File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes A very simple question: not able to understant: Pl help!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "A very simple question: not able to understant: Pl help!!" Watch "A very simple question: not able to understant: Pl help!!" New topic
Author

A very simple question: not able to understant: Pl help!!

Sudeepa Basu
Greenhorn

Joined: May 23, 2001
Posts: 21
Hi friends,
According to JSP specs, variables are declared with the following syntax:
<%! name=value %>
How come the code below which i by chance modified from wrox book works perfectly on java web server. It should give compilation erorr:
<html>
<body>
<% int i = 1; %>
<% for (int x=0; x<5; x++) { out.println("value of i is: is :"+ i); } %>
</body>
</html>
Please tell me the reason. It would be a great help.
thanks a lot in advance
sudeepa
Vijay Kashyap
Ranch Hand

Joined: Jul 30, 2001
Posts: 74
Sudeepa Basu,
Initially you have declared it as a global(instance) variable <%! int i = 0;%>, hence they are shared between different invokation of same jsp.
You have changed it to local variable <% int i = 0;%>, hence its still working. Now the variable i is local variable for method _jspService ( ...), which you would get when jspengine converts your jsp to java file.
Hope this helps,
Vijay
[This message has been edited by vijay kashyap (edited August 29, 2001).]
Sudeepa Basu
Greenhorn

Joined: May 23, 2001
Posts: 21
Thanks a lot vijay.
I got it!
 
 
subject: A very simple question: not able to understant: Pl help!!