Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
124 views
in Technique[技术] by (71.8m points)

java - How does jsp work?

I am wondering does JSP ever get compiled ? The reasons why that I am asking is because whenever I deploy my Java EE application on the web server I only see those servlet and beans class file in the WEB-INF folder as they are compiled, but not that JSP, so how does it work, and what's the logical flow and the big picture of the normal request/response cycle.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Basically:

  • In your servlet container, the JSP servlet is mapped to any URL that ends in .jsp (usually)

  • When one of those .jsp URLs is requested, the request goes to the JSP servlet. Then, this servlet checks if the JSP is already compiled.

  • If the JSP is not compiled yet, the JSP servlet translates the JSP to some Java source code implementing the Servlet interface. Then it compiles this Java source code to a .class file. This .class file usually is located somewhere in the servlet container's work directory for the application.

  • Once the JSP servlet has compiled the servlet class from the JSP source code, it just forwards the request to this servlet class.

The thing is, unless you specifically precompile your JSP, all this happens at runtime, and hidden in the servlet container's work directory, so it is "invisible". Also have in mind that this is what happens "conceptually", several optimizations are possible in this workflow.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...