aspose file tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Help!  Jsp Declaration Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "Help!  Jsp Declaration Question" Watch "Help!  Jsp Declaration Question" New topic
Author

Help! Jsp Declaration Question

Nadine McKenzie
Ranch Hand

Joined: Feb 15, 2002
Posts: 53
Can someone please tell me why this code causes a compilation error?
<html>
<body>
<%! int i; %>
<%! i = 12; %>
Value of i is: <%= ++i %>
</body>
</html>
Isn't
<%! int i; %>
<%! i = 12; %>
equivalent to
<%! int i = 12; %>


Nadine -SCJP, SCWCD, SCBCD
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
<%! %> is the declaration inside this you can place methods or anything you can place OUTSIDE a method in a java class. The following is illegal in Java

This is exactly the type of thing that you are trying to do. You can make this right by removing the !


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
tony lee
Ranch Hand

Joined: Jan 21, 2002
Posts: 52
hi,
<%! int i; %>
<%! i = 12; %>
is not equivalent to
<%! int i = 12; %>
why?
<%! i = 12; %> doesn't satisfy with the defination of a declaration because there's not an identifier for var i. what you intended to do is more like a scriptlet <% i = 12; %>


SCJP2, SCWCD
Sohail Nasim
Greenhorn

Joined: Mar 28, 2002
Posts: 3
How about this one
<%! int i; %>
<% i = 3; %>
<% j = 8; %>
<%! int j = 5; %>
i is <%=i%>
j is <%=j%>
What is the output?
Goan Balchao
Ranch Hand

Joined: Mar 25, 2002
Posts: 93
That should be OK. This is because the declarations are assimilated and declared as instance variables in the page implementation class.
So j is available to the code before it.


Hemant Kamat<br />SCJP2<br />SCWCD<br />SCBCD<br />SCEA-I
 
IntelliJ Java IDE
 
subject: Help! Jsp Declaration Question
 
Threads others viewed
badPage.jsp - HFSJ pg 458
please help me with the ouput
how counter variable works in jsp
JSP-EXCEL save defualt in .xls extension, open excel with in the browser
problem with errorPage and isErrorPage="true"
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture