Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP using getServletContext Error  RSS feed

 
MarkShane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to compile a jsp with the following line of code.
<%@ page language="java" import="java.io.*" %>
<%
String dbPath = getServletContext().getRealPath("/WEB-INF/myData.db");
%>
I keep getting the following error:-
method getServletContext() not found in class.
Any suggestions??.
 
vijith vayanippetta
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
If the real intention is to get the real path you can probably replace that code with this
<%
String realPath =
application.getRealPath("/WEB-INF/myData.db");
%>

application object represents the servletContext and is an implicit object available in jsp.
:-)
 
MarkShane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vijith, it worked.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!