This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JSP and the fly likes variable declaration and removal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "variable declaration and removal" Watch "variable declaration and removal" New topic
Author

variable declaration and removal

Gajan Raj
Greenhorn

Joined: Sep 19, 2003
Posts: 12
Hi
I have a jsp page and id something like this
<%
String str;
use str
%>
html code
<%
String str;
use str
%>
I understand that I can't declare the variable str twice. However is there a way of destoying str after the first use so that it can be declared again...
Regards,
Gajan
Jeffrey Hunter
Ranch Hand

Joined: Apr 16, 2004
Posts: 305
Destroying objects is best left to the JVM. If all you want to do is assign a new value to str, just assign a new value to str (how's that for a recursive answer!):

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32481
    
214

Gajan,
Alternatively, you can put part of the code in its own scope. This is useful if you are including a jsp within another and do not have control over the names.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: variable declaration and removal
 
It's not a secret anymore!