Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getServletContext() method in JSP's generated servlet

 
Kamal Tripathi
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this doubt. Although may not be explicitly relevant for SCWCD.

I use Tomcat container. I wrote a JSP file: result1.jsp. Now I wrote jspInit function in the jsp.



Now this jsp is getting generated and is working fine. But the generated servlet extends org.apache.jasper.runtime.HttpJspBase

and as per api of HttpJspBase getServletContext() method is not listed anywhere. It doesn't even inherit this method from its super-interfaces.

I am just wondering whether this method is present due to vendor implementation because of which getServletContext() is working here.

I was expecting that I'll have to do getServletConfig().getServletContext() in order to get an instance of ServletContext.

 
Kamal Tripathi
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah seems it is another of Tomcat's gift

I put the same thing in weblogic server and this is what I got when I tried to access the jsp.

 
nisha chidella
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this one adds to the list. Tomcat has many issues i guess.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
org.apache.jasper.runtime.HttpJspBase extends javax.servlet.http.HttpServlet, that is why you can access getServletContext(). But, this is not a problem with Tomcat. The problem is that you are looking how the JSP is being translated. You should not rely on what you see, but on what the specification says. If you stick to what the specification says, you know that the page implements javax.servlet.jsp.HttpJspPage, that's all. If you decide to look at the actual implementation and use some accessible methods from there, that's your choice. But then it's you who make the JSP container dependant.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic