JSP技术概览
JSP是一种用于Web应用程序开发的最新的JAVA技术,它是建立在servlet 技术基础之上的。尽管servlet 的功能在很多方面来说都很强大,但它通常属于程序员专有的领域。在本章中,我们将介绍JSP 技术可以解决哪些问题,对JSP 页面的剖析,servlet 和JSP 之间的关系,以及服务器处理JSP 页面的方式等。 JSP is the latest JAVA technology for web application development and is based on the servlet technology introduced in the previous chapter. While servlets are great in many ways, they are generally reserved for programmers. In this chapter, we look at the problems that JSP technology solves, the anatomy of a JSP page, the relationship between servlets and JSP, and how the server processes a JSP page. In any web application, a program on the server processes requests and generates responses. In a simple one-page application, such as an online bulletin board, you don't need to be overly concerned about the design of this piece of code; all logic can be lumped together in a single program. However, when the application grows into something bigger (spanning multiple pages, using external resources such as databases, with more options and support for more types of clients), it's a different story. The way your site is designed is critical to how well it can be adapted to new requirements and continue to evolve. The good news is that JSP technology can be used as an important part in all kinds of web applications, from the simplest to the most complex. Therefore, this chapter also introduces the primary concepts in the design model recommended for web applications and the different roles played by JSP and other JAVA technologies in this model. The Problem with Servlets In many JAVA servlet-based applications, processing the request and generating the response are both handled by a single servlet class. Example 3-1 shows how a servlet class often looks. Example 3-1. A typical servlet class public class OrderServlet extends HttpServlet { public void doGet((HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter( ); if (isOrderInfoValid(request)) { saveOrderInfo(request);
|