This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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(
String dbPassword = getServletContext().getInitParameter(
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.