jsp / getServletContext question

M

Marc E

All,
I've been doing exclusively non-web java work for the past 4 years or so
(i.e. backend console-type apps) and now am getting back into the web side.
To work back into it, I pulled out a site i wrote back in 2002 on Tomcat
4.x. It runs fine on Tomcat 5.5, but Eclipse is giving me this error:
"getServletContext() not found". Now, this is with the tomcat 55 runtime in
the build path.

here's a typical line of code it throws on:

HashMap hm =
Queries.addBaby_Milestone(milestone,getServletContext().getInitParameter("dsn"),request);

please pardon the bad coding... i was brand new at this back then

Eclipse is saying Severity "The method getServletContext() is undefined for
the type __2F_BabyPagesOrig_2F_guestbook_2F_guestbookProcess_2E_jsp
BabyPagesOrig/guestbook guestbookProcess.jsp

Now, if i remember correctly, what I was doing was using web.xml to store
init params like the datasource name ("dsn" above) and using them in an
"application"-scoped manner.

My question, really, is this: what's now the preferred method of A) working
with application-level variables and also B) accessing databases in a
configurable way? I'm not so much worried about eclipse yelling at me b/c i
figure the reason is probably that I'm doing something stupid, even if it
does run.

Thanks for any tips getting me up to speed again.

Marc E.
 
A

Andrea Desole

Marc said:
All,
I've been doing exclusively non-web java work for the past 4 years or so
(i.e. backend console-type apps) and now am getting back into the web side.
To work back into it, I pulled out a site i wrote back in 2002 on Tomcat
4.x. It runs fine on Tomcat 5.5, but Eclipse is giving me this error:
"getServletContext() not found". Now, this is with the tomcat 55 runtime in
the build path.

I don't know what you mean by runtime, but it looks like you have a jar
missing in your classpath. I think servlet-api.jar. You should check the
configuration of your environment
here's a typical line of code it throws on:

HashMap hm =
Queries.addBaby_Milestone(milestone,getServletContext().getInitParameter("dsn"),request);

please pardon the bad coding... i was brand new at this back then

Eclipse is saying Severity "The method getServletContext() is undefined for
the type __2F_BabyPagesOrig_2F_guestbook_2F_guestbookProcess_2E_jsp
BabyPagesOrig/guestbook guestbookProcess.jsp

Now, if i remember correctly, what I was doing was using web.xml to store
init params like the datasource name ("dsn" above) and using them in an
"application"-scoped manner.

My question, really, is this: what's now the preferred method of A) working
with application-level variables and also B) accessing databases in a
configurable way? I'm not so much worried about eclipse yelling at me b/c i
figure the reason is probably that I'm doing something stupid, even if it
does run.

A) I like to use property files
B) JNDI. You can configure data sources on your server and then use them
in your application
 
M

Marc E

Sorry. in my build path, the "Tomcat Runtime" includes a number of jars,
including servlet-api. that's what's weird.

thanks for the tips on the other stuff.
 
A

Andrea Desole

Marc said:
Sorry. in my build path, the "Tomcat Runtime" includes a number of jars,
including servlet-api. that's what's weird.

I can't give you much information about that. I'm afraid you'll have to
manually try some other jar files in the Tomcat installation
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top