• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between servletcontext and application implicit object?

 
viswanath sastry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there a difference between servletcontext and application implicit object?Because I thought they were same.but my code below is confusing me.
Below I present my code,
<%@ page language="java" %>
<%
String datastore = getServletContext().getRealPath("/WEB-INF/mydata.txt");
%>
and I get the error, method getServletContext() not found in class.
And when I replace the method with application implicit object, it works,
<%
String datastore = application.getRealPath("/WEB-INF/mydata.txt");%>
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you reference getServletContext() in your JSP without any qualifications, it -- like any other class -- will try to find the method in the current class. In this case, it is the servlet generated for your JSP -- where, of course, there is no such method.
What about this surprised you?
hth,
bear
 
viswanath sastry
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks bear,
i get it. I should have used getServeltConfig().getServletContext().I didn't realize that getServletConfig() method is available via jspInit and not getServletContext().
Thanks for your prompt reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic