Placing links to the script in generated pages, with the data placed as aparameter

Example

out.println ("<a href =" +

"\"http://athene.csu.edu.au/names.cgi?family=Smith\"");

out.println ("Click here");

out.println ("</a>");

In this example the data item family with the value ‘Smith’ is passed as URLparameter that is given just after the ? mark.

Page7

of10



Cookies

This is another alternative to the problem of statelessness. Cookies are small namevalue pairs used at the client side. Cookies are generally used to store user name andpassword of a user that is used for server side authentication before user is grantedaccess to the server side resources.

Example:

Setting a cookie to a response object.

response.setHeader("Set-Cookie","nationality=Indian");

reading cookie values

String nation;

Cookie[] cookies = request.getCookies();

for (int i=0; i<cookies.length; ++i)

if (cookies[i].getName().equals("nationality"))

nation=cookies[i].getValue();



Session objects

This is the Java solution for the above problem. Java session objects are based onCookies.

Example:

The creation of a session object is done as follows:

HttpSession session=request.getSession(true);

Setting and reading the attribute values in a session object is done as follows:

session.setAttribute("nationality","Indian");

String nation=session.getAttribute("nationality");

3.

Write an introduction to Java Beans by including answers to the followingquestions. What are Java Beans? What are the advantages of using Java Beans?What are the advantages of JSP Tag libraries over Java Beans?

The use of Java Beans in conjunction with our JSP pages can allow us to separate thebusiness logic from the presentation

that leads to 3-tier architecture.The Java Beanwill contain the data that we want to present to the user.The JSP page contains littleor no Java code, but instead just presentation code and code to retrieve the propertiesof the Bean.

A Java Bean is simply an instance of a Java class which encapsulates a series of dataitems (properties).Any Java class which satisfies the following constraints can beused as a Bean class:



It must contain a default constructor, that is a constructor with no parameters



Access to attributes must be through getter and setter methods, which must benamed getSomething or setSomething



We refer to the

values that can be get or set as the properties of the bean (theydon't always have to correspond exactly to the attributes of the Bean)

Page8

of10

Example:

public class BookmarkBean

{

private String title, url, description;

public BookmarkBean () {

}

public void setTitle (String title) {

this.title = title;

}

public String getTitle () {

return title;

}

public void setUrl (String url) {

this.url = url;

}

public String getUrl () {

return url;

}

public void setDescription (String description) {

this.description = description;

}

public String getDescription () {

return description;

}

}

We construct the Bean object just as we would an instance of any Java class:

BookmarkBean bookmark = new BookmarkBean();

We can then call the Bean’s setter methods to set its attributes:

bookmark.setTitle(“ABC Online”);

bookmark.setUrl(“abc.net.au”);

Question-3

15 Marks

Write a

Servlet tocreate a connection to a customer database using the DSN,customerDSN andreadall details in a table named customer and display them as aweb page on a web browser. The customer table includes: custNo (the primary key),custFirstName, custLastName,dateJoined. All these table fields are text

of the below technologiesthat you did notstudy in this subject yet relatedtotheweb applications.

1.

JSON Objects

2.

Web 2

3.

HTML 5

Question-5

(An Additional Question)

15 Marks

Write aJSP code to display the customer details (custNo, custFirstName,custLastName,dateJoined) form a Java Bean that is available in a session object anddisplay them as a web page on a web browser. Consider the name of the bean thatholds customer details as CustomerBean.