Can't get JSP 5.5.x to use my Java 5.0 JDK (it uses an older JDK, even though I think I deleted the older JDK)

I'm using Tomcat 5.5.12 with Windows XP Professional v. 5.1.
I am using JDK 1.5.0_06 and that's been working fine for all my Java applications for 6 months or so.
Whenever I use JDK 1.5 code in a JSP page, I get a compilation error (e.g., for printf or Scanner). My JSP pages work fine if I use JDK 1.4 code (if I use BufferedReader instead of Scanner for reading from a file, it works fine).

I removed my old JDK 1.4 directories from my hard drive and I've verified that they're removed by looking at the directory structure in Windows Explorer.

I've looked on the Internet for compatibility issues and haven't found any. Here's a site that explains how to use Tomcat 5.x with JDK 5.0:

http://www.murach.com/dloads/jsps/jsps_tomcat-5.5.pdf

My system variables point to the jdk1.5 directory, and the system variables do not point to a jdk1.4 directory.

How can I get my JSP pages to work with jdk1.5.x code?

Aside: I'm new to experts exchange:
1. How do I receive answers?
2. How many points am I allowed overall for my one-month subscription?

Thanks,
John
jdean4Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fargoCommented:
Hi,

you need to point the JAVA_HOME variable to the jdk 1.5 path like the following:
JAVA_HOME=C:\java\path

Tomcat uses the JAVA_HOME to compile the jsps etc.
Just set the JAVA_HOME and add the bin directory to path variable. And you are set to go!

fargo
0
jdean4Author Commented:
My system variables were already adjusted as mentioned by fargo. In other words, my JAVA_HOME variable already pointed to my jdk1.5 directory and my path variables (one for my personal login and one for my system variable) both already pointed to my jdk1.5/bin directory.

Does anyone have any other suggestions?
0
radarshCommented:
What is the output of "java -version" on a command line?

________
radarsh
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

jdean4Author Commented:
Radarsh,
Here's what happens when I enter java -version:

C:\Documents and Settings\John Dean>java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)
0
radarshCommented:
How have you compiled your application? Do you get this problem with only JSPs or
with even Java Classes?

Do you have code which uses Generics or Varargs features of JDK 1.5 in your JSP page?
I think you have a source version problem.

If you have to make use of those features of JDK 1.5 (such as the varargs in printf) you
have to compile your Java Source files with a source version of 1.5

On a command line, this should be done using "-source 1.5" switch.


________
radarsh
0
radarshCommented:
0
radarshCommented:
I still want to know for sure if it is a source version error or otherwise.

So, do this simple test in your JSP and let me know what you get.

<%
    int [] array = {1, 2, 3, 4, 5};
    out.println("Array: "+java.util.Arrays.toString(array));
%>

Let me know if you get an output of [1, 2, 3, 4, 5] or a compilation error.

** Please do this befor you try the steps in my previous post.


________
radarsh
0
jdean4Author Commented:
Radarsh et al,

Your suggested Arrays.toString code does work fine.
Actually, I've retested my original code with Scanner and it now works fine as well, so I apologize for not thoroughly testing prior to posting my question. My guess is that when I changed my system variables a month ago to accommodate JDK 1.5, I simply rebooted rather than shutdown completely. That's the only thing I can think of that I've done differently this time around. But I'm far from sure about that hypothesis.

But I still can't use JDK 1.5's printf for formatted output. I tried JSP's out object, but apparently printf is not part of out yet. Can I use printf at all with JSP? I realize that I can use other techniques like DecimalFormat, but I really just want to know definitively about printf with JSP. If someone can definitively say "No, you can't use it, but it will be part of a new JSP release," that would be great.

Thanks,
John
0
radarshCommented:
Alright. In that case, you have to enable special features for JSP compilation.
Go through the article I posted above and follow the steps.

JDK 1.5 comes with lots of new features like printf, generics, varargs, for in loop, etc.
All these will not even compile if you just change your SDK to 1.5. All you have to do is
change your source version. This source version, by default will be 1.4 even in JDK 1.5.

So, while compiling you have to use the -source 1.5 switch (if done in command line)
For Tomcat, however, you have to follow the steps in that link and proceed.

________
radarsh
0
jdean4Author Commented:
As I said above, JDK 1.5 code is now working in my JSP pages.
The problem is now not with JDK 1.5. I just wanted to know if I can mimic printf within JSP.
I can run System.out.printf, but I don't know where the output goes. I was hoping to use JSP's implicit out object and call out.printf, but apparently out does not contain a printf method.

This question is basically a different question than my original question.
My original question resolved itself.
If someone can answer this new question, great, but no big deal if you can't.
0
radarshCommented:
Well, you can't get printf functionality in out object. out is an instance of
JspWriter which inherits from java.io.Writer. On the other hand, System.out is
a PrintStream instance.

In simple words, you CAN'T use it.

>> I don't know where the output goes.
The output will usually be in some log file. In tomcat, it will be under tomcat/logs/tomcat.log


________
radarsh
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jdean4Author Commented:
My workaround is to use String.format. Here's my new code:
  <%= String.format("$%4.2f", (double) totalCost) %>

Thanks,
John
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.