TECHNICALFACILITATION.COM - THE ULTIMATE WEBSPHERE AND JAVA CERTIFICATION GUIDES AND RESOURCES
Google
Download the Completed Solution: 05bjspusebean.ear.

Scroll to the bottom of the page for pertinent code snippets.

Using the JSP useBean Tag

This free, multimedia tutorial shows you how to use IBM's Rational Application Developer (IRAD) 6.0 to create a JSP page that utilizes the jsp:useBean and jsp:getProperty tags. These tags are used to pull a JavaBean out of the HttpSession, and display the state of the JavaBean on the Java Server Page for the user.

If you found something helpful here, please do your part and help support the site. Link to us, buy some books, support our sponsors, tell your developer friends about us, and remember: Happy Java!

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>

<TITLE>timertester.jsp</TITLE>
</HEAD>
<BODY>
<jsp:useBean class="com.examscam.common.Timer" id="timer" scope="session"></jsp:useBean>
<P></P>
<P>Here is the output of our timer:</P>
<BR>Elapsed Time:
<jsp:getProperty name="timer" property="elapsedTime" />
<BR>Start Time:
<jsp:getProperty name="timer" property="startTime" />
<P></P>
</BODY>
</HTML>

package com.examscam.common;

public class Timer implements java.io.Serializable {

private long startTime;

public Timer(){
this.start();
}
public void start() {
startTime = System.currentTimeMillis();
}
public long getStartTime() {
return startTime;
}
public long getElapsedTime() {
return System.currentTimeMillis() - startTime;
}
public void reset() {
startTime = System.currentTimeMillis();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
ExamScamWeb</display-name>
<servlet>
<description>
</description>
<display-name>
CountrySnooper</display-name>
<servlet-name>CountrySnooper</servlet-name>
<servlet-class>
com.examscam.servlet.CountrySnooper</servlet-class>
</servlet>
<servlet>
<description>
</description>
<display-name>
SessionServlet</display-name>
<servlet-name>SessionServlet</servlet-name>
<servlet-class>
com.examscam.servlet.SessionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CountrySnooper</servlet-name>
<url-pattern>/CountrySnooper</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SessionServlet</servlet-name>
<url-pattern>/SessionServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
Google
THE ULTIMATE CERTIFICATION AND WEBSPHERE RESOURCES - BUY THEM NOW ON AMAZON
eXTReMe Tracker