Creating A Home Page Jsp; Compass Travel Tutorial Application - MACROMEDIA 38000382 - JRun - Mac Getting Started Manual

Getting started guide
Table of Contents

Advertisement

Creating a home page JSP

JSPs let you create dynamic pages containing a combination of HTML, Java, and
scripting code. JSPs deliver high performance because the first time that a client requests
a JSP, the page is translated into a Java Servlet and compiled. At runtime, you execute the
compiled servlet.

Compass Travel tutorial application

In the Compass Travel tutorial application, you can browse adventure trip descriptions,
booking information, and make trip reservations. You use HTML, servlets, JSPs,
JavaBeans, and Enterprise JavaBeans (EJBs) to create the static and dynamic portions of
the application.
To get started with the tutorial lessons, see
this chapter, you add JSP code to the tutorial home page and use JSPs to access a
JavaBean that retrieves information from a database.
In the home page of the tutorial application, home.jsp, you code the following JSP
elements:
Home.jsp displays a list of trips a customer can book. This lesson shows how to build a
JSP with embedded Java code to access database information.
To add JSP code to the Compass Adventures home page:
1 In a text editor or a Java IDE, open the file home.jsp located in jrun_root/servers/
2 Where indicated by comments in the file, add the following code:
84
Lesson 2 JSP Tutorial
JSP directives to define page-wide attributes and insert text into a JSP page.
JSP scripting elements to query a database and define statements evaluated on the
server before sending the page output to the client.
tutorial/compass-ear/compass-war.
JSP page
directive
import
<%@ page import="java.sql.*,javax.sql.*,javax.naming.*"%>
JSP
action which calls the header and welcome pages
include
<jsp:include page="header.jsp" flush="true"/>
<jsp:include page="welcome.jsp" flush="true"/>
JSP
directive to insert the footer file text
include
<%@ include file="footer.htm"%>
JSP scriptlet code to query a database for information about adventure trips
<%
java.text.NumberFormat nf = java.text.NumberFormat.getCurrencyInstance();
String sql="SELECT trip_id, name, teaser, price FROM trip";
Connection connection=null;
Statement stmt=null;
ResultSet trips=null;
try {
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource) ctx.lookup("compass");
connection=ds.getConnection();
Lesson 1, "Servlet Tutorial" on page
69. In

Advertisement

Table of Contents
loading

This manual is also suitable for:

Jrun 4

Table of Contents