| Author |
The method getServletContext() is undefined for the type error in jsp page in Eclipse
|
Divya Chandel
Ranch Hand
Joined: Jun 09, 2011
Posts: 43
|
|
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: 56229
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: The method getServletContext() is undefined for the type error in jsp page in Eclipse
|
|
|