`
jayjayjays
  • 浏览: 214787 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JSP Design Notes

    博客分类:
  • java
阅读更多

JSP Design Notes

Introduction to JSP Design Notes

Java Server Pages (JSP's) permit server side Java logic to reside within the requested document. Upon request of a JSP document the server activates the specified JSP. The JSP then becomes responsible for providing an HTML response.

The server side logic within a JSP is written in Java. The Java code segments, referred to as scriptlets, are generally responsible for providing dynamic HTML content to the JSP's response HTML. The JSP itself is compiled by the server, and is executed as an object that extends the Java Servlet API. As such, the HTTP Servlet request and response objects are available by the scriptlets defined within the JSP.

This document reviews client-server design considerations in respect to the use of JSP抯. Implementation options, particularly the use of JSP language extensions and use of Enterprise Java Beans (EJB's) will also be discussed. Focus will be placed on the presentation layer and how the JSP is used to provide a user interface and communicate business logic requests to the supporting system.

If we consider a 3-tier architectural WEB application, the browser becomes the client side application. The user communicates requests to the WEB/app server via the browser. The presentation layer receives the client requests and prepares the response and server side business functionality is executed. In the context of this example, the JSP engine represents the presentation layer. It is responsible for processing requests and responses. Additional messages may be passed between this layer and that which handles business processes represented below as EJB抯.

3-tier architectural web application

Return to Top of Page

The Technology

JSP technology uses XML - like tags and scriptlets. They are used to encapsulate presentation logic within the JSP. They can also initiate messages to distributed or server-side applications. The logical separation of presentation and business logic lies in the implementation of the JSP.

Enterprise Java Beans provide a distinct relationship between the implementation of business logic and the remote interfaces provided to the EJB client. The use of an EJB typically follows the pattern:

  • The client application identifies itself to the server
  • The client application uses the Java Naming Directory service to locate the desired EJB
  • The client application retrieves a handle to the EJB Home and subsequently Remote interfaces.

The remote interface contains methods that the client is permitted to use. They represent a summary of the business logic that is implemented by the bean. The implementation logic is defined within the primary bean class. All IPC, database and resource details are restricted to the bean class.

Return to Top of Page

Prevalent Application

Design constraints and conventions maintain the separation of presentation logic from business logic in the middle tier. Prior to JSP 1.1, a JSP implementation using EJB's might have included various scriptlet sections performing EJB remote interface logic/communication.

Consider the example below:

The JSP is designed to provide a welcome message to an e-commerce user. Assume the request included an HTML name-value pair that identified the (pre-registered) Customer ID.

<html> <title>E-commerce Site</title> <body> <% String CustomerName; String CustomerCompany; String customerID; customerID = (String) pageContext.getRequest().getParameter("CustID"); Context ctx = getContext("some.ejb.jndi.name"); EJBHome home = (EJBHome)ctx.createHomeInterface(); EJBRemote remote = (EJBRemote)home.findCustomer(customerID); CustomerName = remote.getCustomerName(); CustomerCompany = remote.getCustomerCompany(); %> Welcome <%=CustomerName%> we look forward to processing your needs. <br> <%=CustomerCompany%> is one of our favorite companies to work with. </body> </html> 

The resulting JSP is a hybrid of scripting logic and html. In constructing a JSP document, the creation of the HTML base is a prudent step. It becomes the visual template that JSP scriptlets are merged into. The post execution HTML produced from the completed JSP should be that of the original HTML document. With the exception of comment, dynamically generated HTML sections and JSP content substitutions. The scripting logic, except for where desired, is completely non visual in regard to the response HTML text.

The construction of the HTML layout conceivably begins with a Web developer. The creation of the JSP pages would be similar if not identical to the methods used to construct industry HTML pages. The next step would be the addition of JSP specific logic to identify the sections of the HTML that might be generated dynamically. This conversion step from pure HTML to JSP is where server side logic is added to the page.

A completed JSP logically embodies presentation layer services and business functionality. Physically they are blended within the JSP in an as needed swapping of HTML and JSP code. Continued maintenance of the application and changes in the business logic need not affect the presentation layout. Likewise, changes in the presentation layout need not affect the scriptlet logic, it will however require that the WEB developer, not necessarily a JAVA programmer, show care in the handling of this file which is no longer pure HTML should any HTML maintenance become necessary.

Return to Top of Page

The Alternative

A design consideration intended to reduce the complexity of maintaining the HTML aspect of a JSP is to minimize the use of scriptlets in constructing a JSP. Custom tags, introduced in JSP 1.1, can equally produce the functionality provided by JSP scriptlets.

Custom tags are application defined language extensions to Java Server Pages. Custom tags can be used within a JSP in the following ways:

  • to produce html output
  • to produce JSP output (JSP expressions, directives, ...)
  • to create objects
  • to define objects that can be seen as scripting variables within the parent JSP
  • to iterate over a body of JSP/HTML text in a finite manner
  • to determine if section of the calling JSP should be processed or skipped

The goal of using custom tags to minimize the presence of scriptlets is to produce a more HTML ?like JSP. The advantages of this goal are self-evident if we consider projects that expect frequent HTML modifications. Assuming the business logic, pre-presented by the JSP tags, is stable it can be identically merged into various forms of the HTML layout, without explicitly inserting duplicate sections of scriptlet logic (Java code).

Tag handlers implement JSP custom tags. One or more tag handlers can be listed in the Tag Library Descriptor files. References to these files are included in the JSP that intends to use a given tag handler. The tag handler itself is implemented as a Java object that extends the JSP body. Upon execution it has access capabilities to the JSP's Http servlet objects, page attribute and session attribute objects. It can, conceivably, provide a full HTML response to the client in the way that servlets operate. A significant distinction from Java Server Pages is that tag handlers are not designed to be dynamically compiled by the server.

In respect to EJB's, a tag handler accesses an EJB in the same manner as the above scriptlet. It can additionally make available any object it creates, available to other tag handlers and JSP抯. This is accomplished by the use of storage methods that operate within the scope of the page and session. This includes the retention of EJB remote interface objects that can be created once and re-used by subsequent JSP抯 via scriptlets or tags.

The previous JSP example implemented using custom tags might appear as follows:

<%taglib declaration; prefix=tagpre%> <html> <title>E-commerce Site</title> <body> <tagpre:lookupCustomer> Welcome <%=CustomerName%> we look forward to processing your needs. <br> <%=CustomerCompany%> is one of our favorite companies to work with. </tagpre:lookupCustomer> </body> </html> 

As stated previously, the JSP engine and Java Server Pages logically produce presentation layer services. They also provide the interface to business services (i.e. EJB抯). The physical separation of the logic associated with these middle tier components is evident in the above example. The same EJB logic in the previous example is represented here by the tag references.

Figure 2 gives a graphical representation of the physical control flow without the use of custom tags. The client initiates execution with a JSP request. The request via URL is directed to the WEB server that is responsible for servicing such requests. The JSP request triggers the JSP engine to locate and execute the corresponding JSP as a servlet object. The execution of the business logic is represented by the use of Enterprise Java Beans.

physical control flow without the use of custom tags

Logically identical, figure 3 illustrates the use of tag handlers by the JSP. This is the hidden logic implied in HTML example 2.

illustrates the use of tag handlers by the JSP

The JSP engine, in both figures, treats the compiled JSP object as a servlet object. Figure 3抯 tag handler object extends the JSP page body. This relationship grants tag handler access to various servlet attributes. These attributes therefore permit the tag handler to conceivably inspect parameters passed by the client.

Return to Top of Page

Conclusion

As with other tools of the trade, innovations and nuances to existing tools do not invalidate existing design methodologies. They do however provide new versatility and the expansion of possibilities with regard to application design.

Custom tag extensions, in contrast to standard tags, provide the application builder the ability to define custom tags to satisfy some functionality not provided by the standard API. To benefit by using tag extensions to reduce the amount of Java functionality that the JSP API provides, might seem oxymorinic, and it is. With the exception of dynamically compiled JSP抯, the functionality provided by the two given examples are identical, which suggests that the payoff for implementing this server side alternative is purely cosmetic, and it is.

While a server side application designer does not typically consider the cosmetic aspect of implementing source code, JSP source code might prove to be the exception. It does after all suggest the strong possibility that a Web/HTML developer perform the continued maintenance of the HTML portion of the JSP. This is a role, of course, traditionally allied with client side responsibilities.

The nuances introduced by JSP custom tags present nuances in the maintenance of JSP抯. The arguments presented here presume that the HTML produced by the JSP抯 in discussion are non-trivial HTML documents, although non-complex HTML documents may benefit from similar design considerations.

~end of Aurora Information Systems' White Paper Series #9
  "JSP Design Notes"~

分享到:
评论

相关推荐

    JSP Design 第三版

    《JSP设计》第三版是JSP开发领域的一本权威指南,它深入浅出地讲解了如何有效地构建动态Web应用程序。这本书旨在帮助开发者理解和掌握JavaServer Pages(JSP)技术,以便在实际项目中实现高效、可维护和可扩展的Web...

    JSP.rar_jsp_jsp project design_jsp 报表_mvc_报表 java

    **JSP技术** JSP(JavaServer Pages)是Java平台上的动态网页技术,它允许开发者在HTML、XML或其他标记语言中嵌入Java代码,从而实现服务器端的动态内容生成。JSP的核心在于将表现层逻辑与业务逻辑分离,提供更灵活...

    jsp模板 jsp模板 jsp模板jsp模板jsp模板

    jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp模板jsp...

    JSP.design.classic.menu.WEBtree.rar_jsp menu

    本资源"JSP.design.classic.menu.WEBtree.rar_jsp menu"显然是一个关于JSP菜单设计的经典代码示例,特别是使用了WEBtree这一概念来构建菜单结构。 WEBtree通常指的是在Web应用中用来展示层级数据的一种树形结构。在...

    CodeNotes for J2EE - EJB, JDBC, JSP and Servlet

    《CodeNotes for J2EE - EJB, JDBC, JSP and Servlet》这本书是针对Java企业级应用开发的一份宝贵资源,主要涵盖了四个关键的技术领域:Enterprise JavaBeans(EJB),Java Database Connectivity(JDBC),Java...

    Jsp 网站项目web design

    【Jsp 网站项目web design】是一个适合初学者的网上购物网站开发教程,它主要基于HTML(超文本标记语言)进行构建,旨在帮助学习者掌握网页设计和开发的基本概念。HTML是互联网上最基础的页面内容描述语言,通过一...

    antdesign浏览器引用

    AntDesign,全称为"Ant Design",是一款源自阿里巴巴的优秀前端UI框架,专门用于构建企业级的Web应用。它的设计理念是“移动优先”,注重简洁、高效、可扩展性,为开发者提供了一整套完整的组件库,使开发人员能够...

    jsp论坛设计与实现

    jsp论坛设计与实现jsp论坛设计与实现jsp论坛设计与实现jsp论坛设计与实现jsp论坛设计与实现jsp论坛设计与实现jsp论坛设计与实现jsp论坛设计与实现jsp论坛设计与实现jsp论坛设计与实现jsp论坛设计与实现jsp论坛设计与...

    jsp网上商城jsp课程设计

    【标题】"jsp网上商城jsp课程设计"是一个基于JavaServer Pages (JSP) 技术构建的电子商务平台项目。在JSP中,开发者通常利用HTML、CSS和JavaScript来设计用户界面,同时结合Java代码来处理服务器端逻辑。这个课程...

    jsp+mysql简单留言板实现

    list_notes.jsp 发布内容显示和查询结果显示页面 insert.jsp 添加新内容页面 。。。。。。。。。。。。 使用到的数据:db_jsp.sql【位于项目的web页中】 使用方法一: 使用mysql命令行: create database db_...

    JSP.advanced.design.remote.management.rar_Design Management

    动作元素如`&lt;jsp:include&gt;`, `&lt;jsp:forward&gt;`, `&lt;jsp:params&gt;`等,它们提供更高级的功能,如页面包含和转发。 2. **JSP生命周期**:JSP页面在服务器上经历解析、编译、加载、实例化、初始化、服务和销毁等阶段。在...

    jsp * ppt*jsp 教案*jsp 教案

    jsp 教案 jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp 教案jsp ...

    JSP实例代码 JSP实例代码 JSP实例代码 JSP实例代码 JSP实例代码 JSP实例代码

    JSP实例代码 JSP实例代码 JSP实例代码 JSP实例代码 JSP实例代码 JSP实例代码JSP实例代码 JSP实例代码 JSP实例代码 JSP实例代码

    JSP学习资料大全(JSP教程)

    通过《jsp200问》解决实际问题,《jsp全攻略》全面覆盖JSP知识点,《jsp通用模块》教你如何构建可复用组件,《JSP技术手册》是详细的参考文档,《JSP由浅入深》则引导你逐步深入,而《图解JSP环境安装配置》则让你...

    jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序

    jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序 jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序jsp web程序 jsp web程序jsp web程序...

    JSP图书借阅系统(jsp+SQLServer)

    【JSP图书借阅系统(jsp+SQLServer)】是一个基于Java Server Pages(JSP)技术和SQL Server 2000数据库开发的图书借阅管理应用程序。这个系统旨在提供一个高效、用户友好的平台,方便图书馆管理员进行图书的借阅、...

    jsp实用案例教程

    《jsp实用案例教程》是一本由冯燕奎和赵德奎等专家共同编著的专业书籍,主要针对Java Server Pages(JSP)技术,为读者提供了丰富的实践案例,帮助学习者深入理解和掌握JSP在实际开发中的应用。本书不仅讲解了JSP的...

    jsp应用开发详解 jsp电子书

    **JSP应用开发详解** JavaServer Pages(JSP)是一种基于Java技术的动态网页开发工具,它允许开发者在HTML、XML或者其他标记语言中嵌入Java代码,以实现服务器端的程序逻辑。JSP的出现极大地简化了Web应用程序的...

    JSP文件在线预览

    在IT行业中,JSP(JavaServer Pages)是一种用于创建动态网页的技术,它允许开发者使用Java语言来编写网页内容。本文将深入探讨“JSP文件在线预览”这一主题,涵盖其核心概念、实现原理以及相关的技术栈。 首先,...

    structs jsp structs+jsp

    jsp+struct资源 jsp+struct资源 jsp+struct资源jsp+struct资源jsp+struct资源jsp+struct资源jsp+struct资源jsp+struct资源 jsp+struct资源 jsp+struct资源 jsp+struct资源 jsp+struct资源

Global site tag (gtag.js) - Google Analytics