wood burning stoves 2.0*
The moose likes Servlets and the fly likes The method getServletContext() is undefined for the type error in jsp page in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "The method getServletContext() is undefined for the type error in jsp page in Eclipse" Watch "The method getServletContext() is undefined for the type error in jsp page in Eclipse" New topic
Author

The method getServletContext() is undefined for the type error in jsp page in Eclipse

Divya Chandel
Ranch Hand

Joined: Jun 09, 2011
Posts: 46

In my project I am using web.xml to store init params like the datasource name, database URL etc.. and using them in an
"application" which contains jsp pages but when I run the application on Eclipse using Tomcat6 it gives error

Eclipse error-
The method getServletContext() is undefined for the type__2F_StoreManagement_2F_UserInterface_2F_editRule_2E_jsp
StoreManagement is the Main folder of my application and UserInterface contains .jsp pages.

code is like this
String dbURL = getServletContext().getInitParameter("dbURL");
String dbUserName = getServletContext().getInitParameter(
"dbUserName");
String dbPassword = getServletContext().getInitParameter(
"dbPassword");

I don't understand what is the problem.

Divya
SCJP1.6
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60775
    
  65

The first problem is that you have Java code in your JSP. That is a poor practice that has been discredited for almost 10 years now. Time to update your JSP knowledge and move on to the JSTL and the EL.

The 2nd is that in that Java code, you expect a method getServletContext() to exist and it does not.

If you are trying to access context params in a JSP, the correct means is through the implicit EL variable initParams.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: The method getServletContext() is undefined for the type error in jsp page in Eclipse
 
Similar Threads
BMP, Jboss, and mysql configuring
java.sql.SQLException: No suitable driver in DB2 7.01
Get parameter from web.xml file
Converting servlet to a WebSphere JDBC datasource
Problems with encodeURL