• Post Reply Bookmark Topic Watch Topic
  • New Topic

how is the _jspService method?

 
luke brown
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was going through headfirst servlet and jsp, where i found it very confusing that

_jspService()
This method is called from the servlet’s service() method,
which means it runs in a separate thread for each request.
The Container passes the Request and Response objects to
this method.

at the same time it is also mentioned that
the code that we are going to write in our jsp is going to be wriiten inside _jspService method.

now which servlet are they talking about..there might be a case when servlet is not used to call a jsp page..then how we are getting to the jspservice method.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now which servlet are they talking about..there might be a case when servlet is not used to call a jsp page.

The way JSPs are handled by a servlet container is that they get compiled into a servlet - that's the servlet being talked about there. You as the application developer need not concern yourself with these internal workings of the servlet container, but you can see it in action if you look into the contents of the TOMCAT_HOME/work directory; that's where the compiled files of your JSPs are stored.
 
luke brown
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ulf if it is compiled into a servlet then how it is called from the same servlet (it is also copied in the body of _jspService method. )
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what you mean by "how it is called from the same servlet" - it is not *called* by a servlet, it *is* a servlet (well, depending on what you mean by "it" - I'm not clear about that).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fact that the JSP is compiled into a servlet, and how it works internally, are -- as Ulf said -- an implementation detail that you should not have to even think about as a JSP author. My advice is to use your time and energy learning how to write good JSPs rather than wondering how they work internally.

Analogy: rather than learning how the pistons in an engine work, work on your driving skills.
 
luke brown
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:I don't understand what you mean by "how it is called from the same servlet" -


"This method is called from the servlet’s service() method," is what is written in the headfirst book for jsp . if it is the servlet as you said then is it like calling back the same code from within itself .

what i basically want to know here is what and how the _jspService method works...


Regards
Luke
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's not code calling itself, it's the service method calling the _jspService method. Check out the Java source code the JSP gets compiled to which I mentioned. While it does show all this, I'm afraid it may confuse you even more 😊 So you may want to take Bear's advice and just accept it as irrelevant to the web developer.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!