jsp是如何工作的? [英] How does jsp work?

查看:95
本文介绍了jsp是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道JSP会被编译吗?我之所以要问的原因是因为每当我在Web服务器上部署我的Java EE应用程序时,我只会在WEB-INF文件夹中看到那些servlet和beans类文件,因为它们是编译的,而不是那个JSP,所以它是如何工作的,以及正常请求/响应周期的逻辑流程和大图。

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.

推荐答案

基本上:


  • 在servlet容器中,JSP servlet映射到以结尾的任何URL .jsp (通常)

当请求其中一个 .jsp URL时,请求转到JSP servlet。然后,这个servlet检查JSP是否已经编译。

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.

如果JSP尚未编译,JSP servlet会将JSP转换为某些Java源代码实现 Servlet 界面。然后,它将此Java源代码编译为 .class 文件。此 .class 文件通常位于应用程序的servlet容器工作目录中的某个位置。

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.

一次JSP servlet已经从JSP源代码编译了servlet类,它只是将请求转发给这个servlet类。

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

问题是,除非您专门预编译JSP,否则所有这些都在运行时发生,并隐藏在servlet容器的工作目录中,因此它是不可见的。另外请记住,这是概念上发生的事情,在此工作流程中可以进行多项优化。

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.

这篇关于jsp是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆