• Post Reply Bookmark Topic Watch Topic
  • New Topic

how does JSP get transformed to servlet ?  RSS feed

 
nirali shah
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read that jsp is transformed to servlet. How does that happen ?

Servelt has code like "public class SomeServlet extends HttpServlet { ..............."
When a jsp is compiled, how does it derive this code ? what name will this servlet get ? I am confused with this. Please explain this mechanism of jsp getting transformed to servelt.

thanks
 
Mark Williams
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is really up to the web container as to the particulars on how the JSP gets translated into Java code. Looking at the generated source from Tomcat, I can tell you that it does not translate a JSP into an HttpServlet class but it does translate it into something similar.

The answers to your questions really depend on the server implementation you are using. For Tomcat you can specifiy a "work" folder in the application context definition that tells the generated code where to go. Tomcat will name the java and class files differently than say, Websphere.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The process is discussed in this article.
 
Mark Williams
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link Bear. I am still confused though. Why does everyone say that a JSP gets translated into a servlet? Looking at the generated code, the .java looks similar to a servlet but it doesn't appear to actually implement the HttpServlet interface. (or is it HttpServlet super class? I can't check, I am on my iPhone...)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it does. The article does not show the entire class.
 
Mark Williams
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Yes, it does. The article does not show the entire class.


My work computer is forcing me to upgrade Adobe right now so instead of twiddling my thumbs, I got on my laptop and downloaded the source code for Tomcat. I now see that each translated JSP is a class that extends HttpJspBase which extends HttpServlet, which means you are right and I have learned something today. Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what the ranch is for!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!