aspose file tools*
The moose likes Servlets and the fly likes Implicit objects in servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Implicit objects in servlet?" Watch "Implicit objects in servlet?" New topic
Author

Implicit objects in servlet?

Gaurav Daga
Greenhorn

Joined: Jun 19, 2006
Posts: 14
Hi All,

Are there any implicit objects available in servlets..? As for my view is concern there are no implicit objects in Servlet.. But in one of interview I faced recently, interviewer asked me this question and when I said there are no implicit objects available he was not agree with me.

Can any one throw some light on it..?

Cheers,
Gaurav Daga
[ August 13, 2007: Message edited by: Bear Bibeault ]
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
In JSP we have implicit objects that we do not need to bother about.Just use those.As JPS's would get converted to servlets and follow the servlets life cycle.
Straight away you can start using those.All the JPS implicit objects map to some object from servlet specification.Like request means HTTPServletRequest and application means ServletContext.
For better understanding you might want to have a look at the servlet java file translated by the container from the JSP.

In servlets you need to get references yourself.Use getServletContext method to get a reference to it , like this , others too.


Rahul Bhattacharjee
LinkedIn - Blog
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I suppose the best answer would have been "Servlets are Java classes and there is nothing implicit in Java classes".

JSP is a templating language designed to serve as a form of shorthand for creating servlets with lots of string output (HTML & Javascript). Instanciation of the objects most commonly used by such a servlet is taken care of for you by the JSP compiler. That's what implicit objects are.
There is nothing of the sort in Servlets.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Gaurav Daga
Greenhorn

Joined: Jun 19, 2006
Posts: 14
Thanks both of you for your response.

Well my view is also same as you said. Though you may consider HttpServletRequest and HttpServletResponse as implicit object but its not 100% truth.

Anyways I belive there must be some confusion at counter side

Cheers,
Gaurav Daga
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Though you may consider HttpServletRequest and HttpServletResponse as implicit object but its not 100% truth.

Those are not implicit at all. They are available only in the doGet and doPost methods, and there they are passed in explicitly as parameters.


Ping & DNS - updated with new look and Ping home screen widget
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Gaurav Daga:
Though you may consider HttpServletRequest and HttpServletResponse as implicit object but its not 100% truth.


As Ulf mentioned ,those are not implicit objects.

I just wanted to say that for every implicit object in JSP , there is a equivalent object from servlet specification and you have to yourself get the reference to those objects before using those.

Like HTTPServletRequest reference you get from parameter of doXXX and you get reference to ServletContext from getServletContext method.And there are ways to get references to other objects like HTTPSession , servlet config etc .So in case of JSP just start using those implicit objects.If you want to know as how these implicit objects are made available to the JSP programer , then have a look at the servet that has been translated from a JPS file.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It could be that the interviewer was testing your confidence or looking to see if you were answering with a complete understanding of the material or, as many do, trying to get through the interview process with a bunch of memorized facts from interview cheat sheets.
Gaurav Daga
Greenhorn

Joined: Jun 19, 2006
Posts: 14
It seems a solid point.

Anyways thnaks for your response.

Cheers,
Gaurav Daga
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implicit objects in servlet?
 
Similar Threads
Question On jsp ,need help
Question On jsp ,need help
JSP Implicit objects
One issue of Custom tag
Implicit objects