Compiler telling me I have 1.4 JDK when i have 1.5 wont compile generics code

M

Mitch

Hi.

I had written some code which i now plan to deploy (or at least display
its output) using servlets. I have never used servlets before but have
read up on them and am learning as I go. I have finally put a servlet
in amongst my code and am having two major troubles.

1)
My code contains ArrayLists. When i compiled the code before they were
working as expected. Since I have added this code to the
(Automatically generated in NetBeans IDE 4.1) code that outputs the
servlet and jsps in tomcat I get a compiling error on the ArrayLists.

C:\*\src\java\fyp_rail_simulation\RailSimulationSystem.java:46:
generics are not supported in -source 1.4
(try -source 1.5 to enable generics)

As far as i know I have only ever had 1.5 JDK installed on this
machine, and in the projects window if you go to libraries the only two
available in tehre are the "Bundled Tomcat (5.5.7)" and the "JDK 1.5
(Default)".

I have looked through all the generated inf/xml/MF files to find any
references to 1.4 but can not find any. Does anyone have any idea why
this error is occuring or how I might recitify it?

2)
I am unfamilar with servlets, and can find plenty of info on the web
about them, but am having difficulty finding any that give ideas on how
to A) Use anything other than databases and B) Use a servlet as an
addition to existing code rather than creating one from scratch.

For example I would like to go to a page (JSP or servlet) and then from
that page, link to another page which when visited will initialise my
servlet which in turn will intialise my program. Do I still need to
keep the Main method from my existing code [it only contains two lines,
one constructor, and then constructor.run()] or can these be called
from within the servlet succesfully?

Hope that is clear enough, and kind thanks.

Mitch.
 
A

Andrea Desole

Mitch said:
Hi.

I had written some code which i now plan to deploy (or at least display
its output) using servlets. I have never used servlets before but have
read up on them and am learning as I go. I have finally put a servlet
in amongst my code and am having two major troubles.

1)
My code contains ArrayLists. When i compiled the code before they were
working as expected. Since I have added this code to the
(Automatically generated in NetBeans IDE 4.1) code that outputs the
servlet and jsps in tomcat I get a compiling error on the ArrayLists.

C:\*\src\java\fyp_rail_simulation\RailSimulationSystem.java:46:
generics are not supported in -source 1.4
(try -source 1.5 to enable generics)

As far as i know I have only ever had 1.5 JDK installed on this
machine, and in the projects window if you go to libraries the only two
available in tehre are the "Bundled Tomcat (5.5.7)" and the "JDK 1.5
(Default)".

I have looked through all the generated inf/xml/MF files to find any
references to 1.4 but can not find any. Does anyone have any idea why
this error is occuring or how I might recitify it?

this doesn't look like a problem with your compiler, it looks more like
a problem with your settings. Try to change your project settings to
enable 1.5 compatibility. I haven't been using NetBeans lately, so I
can't really tell you how
2)
I am unfamilar with servlets, and can find plenty of info on the web
about them, but am having difficulty finding any that give ideas on how
to A) Use anything other than databases and B) Use a servlet as an
addition to existing code rather than creating one from scratch.

For example I would like to go to a page (JSP or servlet) and then from
that page, link to another page which when visited will initialise my
servlet which in turn will intialise my program. Do I still need to
keep the Main method from my existing code [it only contains two lines,
one constructor, and then constructor.run()] or can these be called
from within the servlet succesfully?

A servlet is just a piece of code that takes an HTTP request and gives
an HTTP response back. In the response the servlet can put anything that
is valid for HTTP, like an HTML page, but also a binary file. The piece
of code that builds your response is in you class derived from
HttpServlet, usually in the methods doGet() or doPost().
So:

A) if you want to do something different you just take the
doGet()/doPost() method and change it. Anyway, if you really need a
basic example of how a servlet works, you can google it. Here are two
from javareference:

http://www.javareference.com/jrexamples/viewexample.jsp?id=101
http://www.javareference.com/jrexamples/viewexample.jsp?id=100

B) concerning your example, a servlet is mapped to a URL, the URL you
send the request to and get the response from; therefore you don't call
the servlet from a page. In the best case you can put a link to it. You
have however a few solutions:
1) the link will point to the servlet, the servlet starts your
application and then redirects/forwards to the page
2) the link will point to a jsp, which can start your program. You don't
need a servlet
3) use a filter:
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Servlets8.html#wp64572


Concerning the main, I wouldn't use it, but it's not really related to
servlets.
 
M

Mitch

Ok I have found that J2EE is at 1.4. There is a J2EE 5 release that I
will try.

Is there any way I can seperate these items? I.E. Have the program
run as it would under 1.5 but only have the servlet abide by the 1.4
restrictions, because the servlet will only be serving xml and doesn't
need advanced features?

TIA for any advice.

Mitch.
 
M

Mitch

It is a problem with the settings for the generics, though it appears i
can't change it (the text area that says that it is J2EE 1.4 is greyed
out. I am installing the new NetBeans and the preview of the J2EE 5
which may solve my problem. Else I may have to convert all my
ArrayLists to arrays which will take hours :(

Thank you for your advice on the servlets, they seem to be relatively
simple to use, at least for what I wish to use them for.

I think it is just a matter of trying to get my J2EE edition up to
speed with ArrayLists else a re-write is in order. Thank you very much
for your input.
 
A

Andrea Desole

Mitch said:
Ok I have found that J2EE is at 1.4. There is a J2EE 5 release that I
will try.

Is there any way I can seperate these items? I.E. Have the program
run as it would under 1.5 but only have the servlet abide by the 1.4
restrictions, because the servlet will only be serving xml and doesn't
need advanced features?

I have to assume now you are mistaking, since it's the second post.
You problem is not J2EE, it's J2SE, which is probably installed
correctly on your machine. Besides, J2EE 5 is still in beta. Stay with
1.4, there is no need for you to go to 5

Concerning the settings, there must be in NetBeans something in the
settings related to the java compiler and the source level, or JDK
compliance, or something like that.
 
M

Mitch

You were right.

I wanted to use many of the automatically generated features that come
with the bundled server so I created a new project of type web app or
similar and this defaulted to the 1.4 source level. When i saw in the
properties section J2EE 1.4 I assumed this is where the problem lied as
all my previous program code was based on the 1.5 source level.

I have since found the scroll box and chosen the right source level and
all seems to be working, or at least compiling.

Thank you, you've helped alot and saved me 700+ lines of re-write. :)

Kind Regards,

Mitch.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top