File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Problem with multiple variable declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with multiple variable declaration" Watch "Problem with multiple variable declaration" New topic
Author

Problem with multiple variable declaration

Michael Jameston
Greenhorn

Joined: Sep 25, 2009
Posts: 4
I am writing a jsp that lets a user pick a favorite technology and then displays the results. The problem is that my declarations keep overwriting the other variables so if you select the third option the first time then the results are correct, however if you choose option one the next time then option 3 goes to 0 and option 1 becomes 1. What could be causing this as I thought the init() method only ran once and initialized these variables.

Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
Hi,
This code is working fine....


Thanks,
Shailesh
Michael Jameston
Greenhorn

Joined: Sep 25, 2009
Posts: 4
Maybe it is just my version of netbeans. I will upload it to another server and give it a try.
Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
netbeans also using Tomcat i think...
I tried on tomcat 5.5.28
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You didn't ask, but just so you know, that JSP struck me as a very odd combination of scriptlet and JSP.

While there's (almost) never any good reason to use scriptlet code in JSP, if you *are* going to use it, it would at the very least make sense to use it appropriately.

Why put some Java code in JSP tags (the variable declarations) and other in scriptlets--doing Java is what scritplets are for? Why generate HTML in scriptlets--doing HTML is what non-scriptlet JSP is for?

Edit: Oh, right; I forgot that <jsp:declaration> creates instance variables. That makes the code even worse, although at least I understand why it's there now. My fault--seriously, I've written exactly one line of scriptlet code in the last five years--can't blame me for forgetting. (Yes, you can; I should have remembered that one.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with multiple variable declaration