Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Divya Chandel
Ranch Hand
Posts: 47
MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64980
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic