Jsp 简明教程

JSP Tutorial

Java Server Pages(JSP)是一种服务器端编程技术,可创建动态、与平台无关的方法来构建基于 Web 的应用程序。JSP 可以访问整个 Java API 家族,包括用于访问企业数据库的 JDBC API。本教程将教您如何使用 Java Server Pages 以简单轻松的步骤开发您的 Web 应用程序。

Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic, platform-independent method for building Web-based applications. JSP have access to the entire family of Java APIs, including the JDBC API to access enterprise databases. This tutorial will teach you how to use Java Server Pages to develop your web applications in simple and easy steps.

Why to Learn JSP?

JavaServer Pages 通常与使用 Common Gateway Interface (CGI) 实现的程序有相同用途。但 JSP 与 CGI 相比提供了几个优势。

JavaServer Pages often serve the same purpose as programs implemented using the Common Gateway Interface (CGI). But JSP offers several advantages in comparison with the CGI.

  1. Performance is significantly better because JSP allows embedding Dynamic Elements in HTML Pages itself instead of having separate CGI files.

  2. JSP are always compiled before they are processed by the server unlike CGI/Perl which requires the server to load an interpreter and the target script each time the page is requested.

  3. JavaServer Pages are built on top of the Java Servlets API, so like Servlets, JSP also has access to all the powerful Enterprise Java APIs, including JDBC, JNDI, EJB, JAXP, etc.

  4. JSP pages can be used in combination with servlets that handle the business logic, the model supported by Java servlet template engines.

最后,JSP 是 Java EE 的一个组成部分,它是企业级应用程序的一个完整平台。这意味着 JSP 可以参与从最简单的应用程序到最复杂、要求最苛刻的应用程序。

Finally, JSP is an integral part of Java EE, a complete platform for enterprise class applications. This means that JSP can play a part in the simplest applications to the most complex and demanding.

Applications of JSP

如前所述,JSP 是 Web 上使用最广泛的语言之一。我将在这里列举其中一些:

As mentioned before, JSP is one of the most widely used language over the web. I’m going to list few of them here:

JSP vs. Active Server Pages (ASP)

JSP 的优势有二。首先,动态部分是用 Java 编写的,而不是 Visual Basic 或其他 Microsoft 专用语言,因此它更强大、更容易使用。其次,它可以移植到其他操作系统和非 Microsoft Web 服务器。

The advantages of JSP are twofold. First, the dynamic part is written in Java, not Visual Basic or other MS specific language, so it is more powerful and easier to use. Second, it is portable to other operating systems and non-Microsoft Web servers.

JSP vs. Pure Servlets

编写(和修改!)常规 HTML 比生成 HTML 的大量 println 语句更方便。

It is more convenient to write (and to modify!) regular HTML than to have plenty of println statements that generate the HTML.

JSP vs. Server-Side Includes (SSI)

SSI 真正只适用于简单的包含,而不适用于使用表单数据、进行数据库连接等的“真实”程序。

SSI is really only intended for simple inclusions, not for "real" programs that use form data, make database connections, and the like.

JSP vs. JavaScript

JavaScript 可以动态地在客户端上生成 HTML,但很难与 Web 服务器交互以执行诸如数据库访问和图像处理等复杂任务。

JavaScript can generate HTML dynamically on the client but can hardly interact with the web server to perform complex tasks like database access and image processing etc.

JSP vs. Static HTML

当然,常规 HTML 不能包含动态信息。

Regular HTML, of course, cannot contain dynamic information.

Audience

本教程专为初学者编写,以帮助他们了解 Java Server Pages (JSP) 的基本功能,以开发您的 Web 应用程序。完成本教程后,您会发现自己在使用 JSP 方面已经具备了中等水平的专业知识,您可以从那里提升自己的技能。

This tutorial has been prepared for the beginners to help them understand basic functionality of Java Server Pages (JSP) to develop your web applications. After completing this tutorial you will find yourself at a moderate level of expertise in using JSP from where you can take yourself to next levels.

Prerequisites

我们假设您对 Web 应用程序如何在 HTTP 上工作、什么是 Web 服务器以及什么是 Web 浏览器了解得不多。如果您对使用任何编程语言进行 Web 应用程序开发有一些了解,那就太好了。

We assume you have little knowledge of how web applications work over HTTP, what is web server and what is web browsers. It will be great if you have some knowledge of web application development using any programming language.

Frequently Asked Questions about JSP

关于 JSP 有一些非常常见的常见问题 (FAQ),本部分尝试对这些问题进行简要回答。

There are some very Frequently Asked Questions(FAQ) about JSP, this section tries to answer them briefly.