Article: Java Server Pages

Topics: JavaServer Pages, Java Community Process, Web server Pages: 12 (1783 words) Published: February 6, 2013
Java Server Pages combined with servlets in action
We want to create a small web application (library), that illustrates the usage of JavaServer Pages combined with Java Servlets. We use the JavaServer Pages to display data (presentation) and the servlets to control and call the business logic of the web application. First we shortly explain the characteristics of these two technologies.

Sascha Wolski
Tutorials for Struts, EJB, xdoclet and eclipse.
September, 23th 2004
Source code: The sources does not contain the project files. So create a project first and copy the sources to this projects.
PDF Version des Tutorials: Development Tools
Eclipse 3.x
MyEclipse plugin 3.8
(A cheap and quite powerful Extension to Eclipse to develop Web Applications and EJB (J2EE) Applications. I think that there is a test version availalable at MyEclipse.) Application Server
Jboss 3.2.5
You may use Tomcat here if you like.

Java Servlets
Servlets represent java programs that run on a web server. They allow the developer to produce dynamic web sites with java.
A Servlet has the following tasks

It reads and processes data, which a user inputs in a HTML form on a web page.

Other informations can be processed, e.g. what browser or system will be used.

It generate results with the existing data, calls the business logic directly in the servlet or another class, which contains the logic or executes a database query.

The results are formated. If the Browser expects an answer in the HTML format, then the results must be formatted in accordance with the standard. It is possible to return different formats of data with a servlet. (gif, jpeg, doc, etc.).

Suitable answer parameters are set. Befor the servlet return the data to the browser, it sends some parameter. The parameter contains the format, that will returned by the servlet, what time the browser use to cache the site and some more.

Java Server Pages (JSP)
JavaServer Pages (JSP) are text documents, which are similar to HTML Files. But you find also java code in the JSP File. JavaServer Pages allow you to mix regular static HTML with dynamic generated contents of Java code. The java code is inserted in the HTML document on a JSP File, differently to a servlet, where the HTML code is embedded in the java code.

Create a new Web Projekt
Right click on the package explorer and choose New > Project. Choose the wizard Web Project in J2EE.

Set a nice name for your project.

Class with dummy data
In this example we do not use a database binding. We use a class which provide the dummy data and some methods for add, update, delete. Create a new Package de.laliluna.tutorial.library in src of the project. Download the complete project an copy the file from the folder /de/laliluna/tutorial/library in the package.

Create the class book
You can borrow a book in a library, so we need a class that represent the book. Create a package de.laliluna.tutorial.library and a new class New > Class.

The object class book contains the following private properties as variables. •





We create for the properties getter- and setter-methods, to access the private properties. Open the class Book and add the properties and getter- and setter-methods. Add constructors to this class.

public class Book {

long id = 0;
String title = "";
String author = "";
boolean available = false;

// Contructor
public Book(){}
// Contructor to initial the properties
public Book(long id, String author, String title, boolean available) { = id; = author;
this.title = title;
this.available = available;
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Java Essay
  • Java Essay
  • Advanced Java Essay
  • server 2008 Essay
  • Essay on Java
  • Java Research Paper
  • java Essay
  • Java Essay

Become a StudyMode Member

Sign Up - It's Free