Computer Science Department, Bucknell University

CSCI 479 Capstone CS Desgin
JavaServer Pages (JSP)
By Professor Dan Hyde, Fall, 2009

Introduction

Since you are designing a web-based application, you could implement your project as JavaServer Pages (JSP), Java applets or a combinations of the two.

JavaServer Pages (JSP) is Sun Microsystems' answer to Microsoft's ASP (Active Server Pages). JSP is Java code embedded as tags in the HTML (or XHTML). JSP is easier to use than Java Servlets especially if you are a web-page designer who most of time wants to present static text with HTML or XHTML and incorporate only a few dynamically generated features.

A good reference on JavaServer Pages (JSP) is Chapter 29 in our Java text.

In order to use JSP you need to run a tomcat server. If you have a PC, you can download tomcat for free.

tomcat Server

I asked ECST to install a tomcat on a Linux machine so we could play with JSP. Point your browser at

http://www.linux.bucknell.edu:9004/

to see the standard startup page and documentation that comes with the recent version of tomcat. Note that some links are password protected. Try the JSP examples.

Sample JSP program

To try a JSP program that I wrote, point your browser at

http://www.linux.bucknell.edu:9004/hydeTest/clock.jsp

Below is the JSP code for the clock example to provide you a flavor of JSP.


<?xml version = "1.0"?>
<!DOCTYPDE html PUBLIC "-//W3C/DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv = "refresh" content = "60" />
    <title>A Simple JSP Example</title>
    <style type = "text/css">
       .big { font-family: helvetica, arial, sans-serif;
              font-weight: bold;
              font-size: 3em;}
    </style>
  </head>
<body>
<center>
     <p class = "big">Simple JSP example based on example<br>
from <i>Java: How to Program</i> <br>
by Deitel and Deitel, 6th edition,
    page 1283.<br>
Time and date is refreshed every 60 seconds.
</p>
     <table style = "border: 6px outset;">
       <tr>
         <td style = "background-color: black;">
           <p class = "big" style = "color: cyan;">
            <!-- JSP expression to insert time and date -->
	         <%= new java.util.Date() %>
           </p>
          </td>
        </tr>
      </table>
</center>
</body>
</html>

Below is a JSP program that uses a Java Applet to convert temperatures. The original temperature application is an example Java program done in CSCI 203.

http://www.linux.bucknell.edu:9004/hydeTest/temperature.jsp

Below is the JSP code for the temperature example.

<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- temperature.jsp , the class files are in same directory as  
     .jsp file -->

<html xmlns = "http://www.w3.org/1999/xhtml">

   <head>
      <title>Temperature Conversion Applet</title>
   </head>

   <body>

        <h1>Using Java Applet.  You can enter temperatures in either field.
        </h1>

       <applet code = "TempConvert.class" width = "200" height = "80">
        </applet>

        <h1>After Applet
        </h1>
   </body>
</html> 

Original Java Application


Details