All Examples

Package Index

JavaServer Pages (JSP) examples

Here are links to the source code for the example JSP pages in alphabetical order.

about these examples

These examples show how to use JSP to generate interactive web pages, using embedded Java. JSP allows you to concentrate on the design of HTML pages, but still use Java to provide the dynamic content and logic. These examples demonstrate:

Here is a short description of each JSP example, ordered by complexity. The (run) link after each page will request the actual JSP page itself. This link will only work if you are requesting the JSP page via a JSP-enabled server, such as the WebLogic Server.

HelloWorld.jsp (run)
This simple example demonstrates how to embed Java in an JSP page.
ShowDate.jsp (run)
Demonstrates importing a package (java.util.Date), setting a response header attribute, and using a JSP expression tag.
ErrorPage.jsp (run) & ThrowException.jsp (run)
Demonstrates how you can set up an error page for another JSP page. Here, ErrorPage.jsp is returned when an uncaught exception is thrown in the page ThrowException.jsp.
SimpleDBLogin.jsp (run)
Illustrates how to make a connection to a database with JDBC, including exception handling to help you debug your servlet. This example requires you to set up the "demoPool" Cloudscape database, as described in the techsupport document Using the Cloudscape database with WebLogic.
EasyTableDataDisplay.jsp (run)
Shows how to create an HTML table from a dbKona TableDataSet with minimum effort. This example uses a handy feature of htmlKona that creates an HTML table automatically from a JDBC DataSet. To run the example, you will need to set up the demoPool JDBC connection pool, as described below.
InteractiveQuery.jsp (run)
Connects to a database, and displays it's contents in a table. You can click on an entry in the table, which makes another query to this JSP page. The page interprets the request differently since there are HTTP query parameters present, and displays the name of the entry you selected.
JdbcTable.jsp (run)
Shows how to use a form to set options for retrieving database data from a table with JDBC. This example uses the demoPool JDBC connection pool, as described below.
SessionServlet.jsp (run)
Shows how to store and retrieve user data in a session. The example allows you to add or delete name/value attributes to and from an HTTP session, much the same as a shopping cart would work. The same session containing the user values is retrieved each time the browser revisits the web page, and is displayed in a list. This is achieved using session cookies. For more details see Using session tracking from a servlet.
SnoopServlet.jsp (run)
Lets you examine HTTP data about the servlet itself.
URLEncode.jsp (run)
Demonstrates how URL rewriting works, for passing session information to the server from browsers that don't support cookies.
EJBeanManagedClient.jsp (run)
Demonstrates using JSP to call a WebLogic EJBean, how to use an EJBean from within a scriplet page. It uses a bean-managed entity EJBean included with the WebLogic Distribution. Before you try to run this example, you'll need to compile, configure, and deploy the EJBean that this example depends upon; please see the bean-managed persistence example and the WebLogic EJBean examples for instructions.

how to use this package

  1. In the weblogic.properties file of your WebLogic Server, you must enable JSP pages. Look for and un-comment the following lines:
      weblogic.httpd.register.*.jsp=\
             weblogic.servlet.JSPServlet
      weblogic.httpd.initArgs.*.jsp=\
             pageCheckSeconds=60,\
             packagePrefix=examples.jsp,\
             compileCommand=c:/java/bin/javac.exe,\
             workingDir=/weblogic/myserver/classfiles,\
             verbose=true
    
    To run these examples, set pageCheckSeconds to 0, and ensure that compileCommand points to a valid java compiler. For more details on setting up JSP in WebLogic, see the administrators guide, Setting up JSP.

  2. You'll need to set other properties and change a few variables in the JSP files to match your environment. Additional setup requirements are described with the appropriate examples below.

  3. Many of the examples use JDBC to access an example Cloudscape database called "demoPool". The Cloudscape DBMS and a default database are provided with the WebLogic Server installation. For more details on how to configure Cloudscape and the example "demoPool" database, see the tech-support document Using the Cloudscape database with WebLogic.

  4. Make sure that the document root is configured. Look for the property:
      weblogic.httpd.documentRoot=public_html
    Your JSP files must live below the document root directory. The document root is the top level directory for files that are publically available on your WebLogic Server, and it is the root directory where JSP files are searched from. For more details, see Setting up a document root.

  5. Set your document root to public_html (as above), then copy this entire examples\jsp directory to C:\weblogic\myserver\public_html\jsp. Now, start the WebLogic Server on your local machine, and request this page again via the URL: http://localhost:7001/jsp/index.html. You are now requesting all html and jsp files via your WebLogic Server, and will be able to simply click on the (run) links above to run the JSP files.

  6. Start the WebLogic Server.

  7. To call a page, access the page using a URL such as:
      http://localhost:7001/jsp/HelloWorld.jsp
    or click on the (run) links above once you are viewing this page via the WebLogic Server.

there's more

Read more about JSP in the Developers Guide, Using WebLogic JSP.

Other Developers Guides that may be of interest for the examples in this directory are:

There are also Developers Guides for each of the JDBC drivers.

Copyright © 1999 BEA WebXpress, Inc. All rights reserved.

Last updated 08/23/1999