This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "declaration" Watch "declaration" New topic
Author

declaration

Anoopriya Muthuswaami
Greenhorn

Joined: Nov 20, 2008
Posts: 25
Consider the following example
<%! String str="Hello"; %> //this becomes instance variable in generated servlet

<% String str="GoodDay"; %>//this becomes local variable in service method
<%= str %>

The result of this is GoodDay.

My question is how do I print the value 'Hello'?
Matteo Palmieri
Greenhorn

Joined: Sep 09, 2008
Posts: 28
This should do the case:


SCJP1.4: 96% SCWCD5: 91%
Anoopriya Muthuswaami
Greenhorn

Joined: Nov 20, 2008
Posts: 25
Thanks.. It worked.
Tuna Töre
Ranch Hand

Joined: Aug 17, 2008
Posts: 219

good question... Anoo Raj


blog: http://tunatore.wordpress.com
SCJP 6.0 + SCWCD 1.5
 
Don't get me started about those stupid light bulbs.
 
subject: declaration
 
Similar Threads
variable declaration and removal
Strings immutable
Comments on the fly
declarations and scriptlets
How to forward a page from catch block