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.
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.
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>
To use JSP, you need to set up a Tomcat server on the Linux Tomcat machine. ECST must be informed and they will set up your account for you.
To install a Tomcat server you need to email "ecst@bucknell.edu" with the account name, e.g., cs479a, you want for the Tomcat server. Mike Harvey or Jeremy Dreese will add a bunch of files to the account and provide you with information including the port number to use. The files are placed in new directory
~account/apache-tomcat/Also, they will adds some lines to the account's .cshrc file.
The static content of your web site (HTML pages, JSP pages, JavaScript files, CSS stylesheet files, and images) that you want accessible to application clients should be placed in "myProject". This directory will be the document root of your web application, and any subdirectory structure found here will be reflected in the request URIs required to access those files.
setenv CLASSPATH /usr/local/apache-tomcat/lib/servlet-api.jar:$CLASSPATH
This should have been done for you by ECST.
In your web browser, type the following URL to use your servlet
http://www.linux.bucknell.edu:port/myProject/prog.jsp