Chinaunix首页 | 论坛 | 博客
  • 博客访问: 553990
  • 博文数量: 155
  • 博客积分: 7055
  • 博客等级: 少将
  • 技术积分: 1700
  • 用 户 组: 普通用户
  • 注册时间: 2004-11-22 11:40
文章分类

全部博文(155)

文章存档

2016年(1)

2011年(2)

2010年(1)

2009年(2)

2008年(9)

2007年(39)

2006年(58)

2005年(38)

2004年(5)

我的朋友

分类: LINUX

2006-11-09 18:33:29

* 一个原因是JSP建于Java Servlets API之上,能访问所有的Enterprise Java APIs,如JDBC JNDI JavaBeans

* 另一个原因是JSP在 WEB应用领域非常强悍,这个要从头说起
早先,要开发动态的WEB内容,只能使用CGI。它定义了,web server如何把用户输入递交给程序,程序如何把动态处理的结果交给web server,最后返回给用户。
CGI脚本一般用Perl来写。
其不足在于:对每一个请求输入, web server都要建立一个新进程,装入perl解析器和perl script,然后才能开始处理。完成后,做清理工作。

这样当请求不断增多时,服务器就不堪重负了。
于是人们做了一些改进,也发明了一些新的方法。如FastCGI, Apache的mod_perl, Netscape的NSAPI,微软的ISAPI,SUN的Java Servlets。
效果是有的,但它们都面临一个问题:web页面的生成是在相关的编程语言中嵌入HTML,于是这个工作只能是程序员来做了。
JSP解决了这个问题,那就是反其道而行之,在HTML页面中嵌入Java程序。

* JSP比CGI/Perl 还有一个好处。perl是解释性语言,无须编译,方便。但服务器就惨了,每次来个页面请求,在执行前它都要解释一遍。烦!
JSP就不一样了,只须在第一次访问时编译为执行代码,之后的访问,就是直接执行了。

from JSP - Java Server Pages 2nd Edition - O'Reilly - 2002.pdf

In the early days of the Web, the Common Gateway Interface (CGI) was the only tool for developing dynamic web content. However, CGI is not an efficient solution. For every request that comes in, the web server has to create a new operating-system process, load an interpreter and a script, execute the script, and then tear it all down again. This is very taxing for the server and doesn't scale well when the amount of traffic increases. Numerous CGI alternatives and enhancements, such as FastCGI, mod_perl from Apache, NSAPI from Netscape, ISAPI from Microsoft, and Java servlets from Sun Microsystems, have been created over the years. While these solutions offer better performance and scalability, all these technologies suffer from a common problem: they generate web pages by embedding HTML directly in programming language code. This pushes the creation of dynamic web pages exclusively into the realm of programmers. JavaServer Pages, however, changes all that.

JSP tackles the problem from the other direction. Instead of embedding HTML in programming code, JSP lets you embed special active elements into HTML pages. These elements look similar to HTML elements, but behind the scenes they are actually componentized Java programs that the server executes when a user requests the page.

Another benefit that is important to mention is that a JSP page is always compiled before it's processed by the server. Remember that older technologies such as CGI/Perl require the server to load an interpreter and the target script each time the page is requested. JSP gets around this problem by compiling each JSP page into executable code the first time it's requested (or on demand), and invoking the resulting code directly on all subsequent requests. When coupled with a persistent Java virtual machine on a JSP-enabled web server, this allows the server to handle JSP pages much faster.

阅读(980) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~