JSP Access to the Database to Display Unformatted Results



JSP Access to the Database to Display Unformatted Results

Due: Wednesday, October 31 in 433 class

JavaServer Pages (JSP) technology enables rapid development of web-based applications enabling you to separate the dynamic part of your pages from the static HTML. JSPs look like a cross between HTML and Java codes and allow one to embed intelligent data into normal HTML pages. For example, we cannot have an if...then or for...loop inside Html page, but with JSP it is possible. Theoretically, you can have any valid Java code inside a JSP.

JSP technology uses XML-like tags and scriptlets written in the Java programming language to encapsulate the logic that generates the content for the page. Additionally, the application logic can reside in server-based resources, which the page can access with these tags. Any and all formatting (HTML or XML) tags are passed directly back to the response page. By separating the page logic from its design and display and supporting a reusable component-based design, JSP technology makes it faster and easier than ever to build web-based applications.

In this assignment you will be developing JSPs to access the database and display unformatted results.

Phase I: Creating a connection to the database

Before you can access any data from the database you need to create a connection to the database. To begin we you can use any editor you wish (notepad will do fine). The connection can be done by:

As you can see the Java code can be placed inside the HTML code by using the following tags:

. Between tags, any valid Java code is called a Scriptlet.

is a JSP directive that lets you import all the java.sql.* classes into the current JSP page. A JSP directive gives special information about the page to the JSP Engine. Directives do not produce any visible output when the page is requested but change the way the JSP Engine processes the page.

You can get the class object associated with the given driver: COM.ibm.db2.jdbc.app.DB2Driver

Then establish a connection to the given database URL with the appropriate username and password:

jdbc:db2:database_name","user_name","user_passwd

Phase II: Getting data from the database and displaying on the JSP page

Now that you have opened a connection you need to get data from this database and display it.

Query, insert, delete, modify data from one or more tables with some application logic. Create a series of JSP pages that link to each other. For example you could create one JSP for a login page and carry that user name and password to the next employee page.

You can use your Stored Procedures you wrote in the previous assignment to execute queries, inserts, delete, etc. and call it from your JSP to display the results.

A sample JSP code for getting the data out of the database:

Save you JSP pages in your group folder (\\egret.csuglab.cornell.edu\database_name) as .jsp

You can execute your JSPs through the browser by typing the path where you stored your JSP files:

What to “submit”:

Create a file that includes the following information:

- The names and netids of all group members

- For each JSP, write a brief description of the logic and what is displayed.

Also submit:

- All you JSP pages (atleast 2 pages)

Put this in a folder named JSPAssign and place into your database directory on egret.

If you have any further problems, contact the teaching assistants.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download