• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implicit objects in servlet?

 
Gaurav Daga
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gaurav Daga
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems a solid point.

Anyways thnaks for your response.

Cheers,
Gaurav Daga
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic