Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

jsp / getServletContext question

Thread view: 
Marc E - 19 Jun 2006 00:23 GMT
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.
Andrea Desole - 19 Jun 2006 09:03 GMT
> All,
>   I've  been doing exclusively non-web java work for the past 4 years or so
[quoted text clipped - 3 lines]
> "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:
>
[quoted text clipped - 16 lines]
> 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
Marc E - 19 Jun 2006 12:22 GMT
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.

>> All,
>>   I've  been doing exclusively non-web java work for the past 4 years or
[quoted text clipped - 32 lines]
> B) JNDI. You can configure data sources on your server and then use them
> in your application
Andrea Desole - 19 Jun 2006 12:40 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.