Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

getServletContext() method in JSP's generated servlet

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this one adds to the list. Tomcat has many issues i guess.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic