WTP Tutorials - Building a CMP Based School Schedule Web Application
WTP Tutorials - Building a CMP Based School Schedule Web Application
 

By Jason Sholl
September 11, 2005

 

In this tutorial you will create a CMP based school schedule Web application. You will learn how to create a Container Managed Entity Bean to store the schedule. A Session bean will be used to interact with the CMP. A JSP and Servlet will serve as the front end. The Web portion of this tutorial was adapted from the Building a School Schedule Web Application tutorial by Lawrence Mandel.

Prerequisites For The Tutorial
 
  1. Web Tools Platform (WTP) project
    The WTP project can be downloaded from http://download.eclipse.org/webtools/downloads/

  2. Tomcat 5.0.28
    Tomcat is available from http://jakarta.apache.org/tomcat/

  3. JDK 1.4.2
    Sun's JDK is available from http://java.sun.com/j2se/1.4.2/download.html

  4. JBoss 3.2.3
    JBoss is available from http://www.jboss.org/products/jbossas/downloads

  5. XDoclet 1.2.3
    XDoclet is available from http://xdoclet.sourceforge.net/xdoclet/install.html

Creating An EJB Project
 

The first step is to create an EJB project for the EJB Module

 
  1. Select File -> New -> Project-> EJB -> EJB Project


  2. Click Next and fill in 'ScheduleEJB' for the EJB project name, expand the advanced section and fill in 'ScheduleEAR' for the EAR Application name, uncheck EJB client JAR support, and check Add Support for Annotated Java Classes


  3. Click the 'New' button next to the Server Target Dropdown and then expand Generic Example and select 'Generic JBoss 3.2.3'


  4. Click Next and fill in the location of your JBoss installation and click finish.


  5. Now back in the EJB Project wizard, change the EJB version to 2.0 and select your newly created server target and click finish.


  6. Once the wizard finishes, switch to the J2EE Perspective and see your newly created EJB Project


Creating An EJB Session Bean
 

Now you will create a Session bean in the ScheduleEJB EJB project.

 
  1. Select File -> New -> Other-> EJB -> Enterprise Java Bean


  2. Click Next


  3. Click the 'preferences' link to specify your annotations provider. Now, enable the builder, fill in the location of your XDoclet installation, and select its version.


  4. Also, be sure to specify JBoss under both the EJB and Web preferences and set the versions to 3.2 and 3.2 respectively. Finally, click ok.




  5. Now back in the Session Wizard, click next. Fill in 'ejbs' for the package, 'ScheduleSessionBean' for the class name, and be sure check the box for generating annotated beans.


  6. Click finish to create your Session bean and see it in the Project Explorer. The annotations builder should have run and generated local and remote, and local and remote home interfaces.


 

It is important to remember when developing EJBs using XDoclet to only edit the actual bean classes (e.g. ejbs.ScheduleSessionBean). All deployment descriptor metadata, as well as the various EJB interfaces are generated using the XDoclet javadoc tags. If you open ScheduleSessionBean, you can see some of these tags. Full documentation on how to use these tags can be found in the XDoclet docs.

 
 
 
Creating A CMP Bean
 

At the time of this writing, there is no tooling support Entity beans. Entity beans may be created, however, using JDT tools and XDoclet tags.

 
  1. Select File -> New -> Other-> Java -> Class -> And fill in the following information: Package: ejbs, Name: ScheduleItemBean, Superclass: java.lang.Object, Modifiers: public and abstract, Interfaces: javax.ejb.EntityBean. Then click finish.


  2. Now, open ejb.ScheduleItemBean.java in the Java editor. XDoclet tags need to be added in order for XDoclet to properly generate all the necessary code and ejb meta data. Start by adding the following javadoc to the bean class itself (right above the line: public abstract class ScheduleItemBean). This code specifies that this bean is a CMP, should only have local interface, defines the interfaces names, and specifies that the primary key is type java.lang.Integer and is handled by field 'id'.

    /**
     * Bean implementation class for Entity Bean: ScheduleItem
     * 
     * @ejb.bean name="ScheduleItem" type="CMP" cmp-version="2.x"
     *           schema="ScheduleItem"
     *           local-jndi-name="ejb/ejbs/ScheduleItemLocalHome" view-type="local"
     *           reentrant="true" primkey-field="id"
     * 
     * @ejb.home local-class="ejbs.ScheduleItemLocalHome"
     * 
     * @ejb.interface local-class="ejbs.ScheduleItemLocal"
     * 
     * @ejb.pk class="java.lang.Integer"
     */
    
  3. Now add the necessary getters/setters and XDoclet tags for the primary key.

    	/**
    	 * @ejb.persistence read-only="false"
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract Integer getId();
    
    	/**
    	 * @ejb.persistence
    	 */
    	public abstract void setId(Integer id);
    
  4. At this point, if you save ScheduleItemBean, the XDoclet builder should run cleanly.


  5. Now, to add a few more CMP attributes to ScheduleItem bean, add getters/setters and XDoclet tags
    	/**
    	 * @ejb.persistence read-only="false"
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract java.lang.String getName();
    
    	/**
    	 * @ejb.persistence
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract void setName(java.lang.String newName);
    
    	/**
    	 * @ejb.persistence read-only="false"
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract int getStartTime();
    
    	/**
    	 * @ejb.persistence
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract void setStartTime(int newStartTime);
    
    	/**
    	 * @ejb.persistence read-only="false"
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract int getEndTime();
    
    	/**
    	 * @ejb.persistence
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract void setEndTime(int newEndTime);
    
    	/**
    	 * @ejb.persistence read-only="false"
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract int getDay();
    
    	/**
    	 * @ejb.persistence
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract void setDay(int newDay);
    
    	/**
    	 * @ejb.persistence read-only="false"
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract java.lang.String getScheduleID();
    
    	/**
    	 * @ejb.persistence
    	 * @ejb.interface-method view-type="local"
    	 */
    	public abstract void setScheduleID(java.lang.String newScheduleID);
    
  6. Next is to add a means by which to create ScheduleItemBean. The create method will take the Name for the new ScheduleItem and autogenerate a new key. The rudimentry key generation code is for example purposes only. After you paste the code below, do an organized imports (Control-Shift-o) to add an import for CreateException.
    private static int PRIMKEY = (int) System.currentTimeMillis();
    
    	/**
    	 * ejbCreate
    	 * 
    	 * @ejb.create-method view-type="local"
    	 */
    	public java.lang.Integer ejbCreate(java.lang.String name)
    			throws CreateException {
    		setId(new Integer(PRIMKEY++));
    		setName(name);
    		return null;
    	}
    
    	/**
    	 * ejbPostCreate
    	 */
    	public void ejbPostCreate(java.lang.String name) throws CreateException {
    	}
    
  7. The last step is to add a few finder definitions. These should be added to the class level javadoc (right below the @ejb.pk class definition added before).
     * @ejb.finder signature="java.util.Collection findAll()" query="select
     *             object(o) from ScheduleItem o"
     * 
     * @ejb.finder signature="java.util.Collection findByScheduleID(java.lang.String
     *             scheduleID)" query="select object(o) from ScheduleItem o where
     *             o.scheduleID = (?1)"
     * 
     * @ejb.finder signature="java.util.Collection findByName(java.lang.String
     *             name)" query="select object(o) from ScheduleItem o where o.name =
     *             (?1)"
    
  8. At this point if you save and build, you should be abloe to open ScheduleItemLocal and ScheduleItemLocalHome and see all method stubs were appropriatly generated. Do not edit these files. Once you are done inspecting them, close them both.




Adding purpose to ScheduleSessionBean
 
  1. If ScheduleSessionBean is not open, open it in the JavaEditor. The first thing we need to do is add a local reference from the ScheduleSessionBean to the ScheduleItemLocal. This requires the following XDoclet tag at the class level (put this right below the * @ejb.bean name="ScheduleSession" block). The second tag which starts with @jboss.ejb-local-ref is a JBoss specific XDoclet tag used to setup the JNDI name; other vendors also have their own specific tags where needed.
     * @ejb.ejb-ref ejb-name="ScheduleItem" view-type="local"
     * 
     * @jboss.ejb-local-ref ref-name="ScheduleItemLocal"
     *                      jndi-name="ejb/ejbs/ScheduleItemLocalHome"
     * 
    
  2. Since ScheduleSessionBean will be used by the forthcoming web client instead of ScheduleItemBean, it is necessary to add a few methods to access ScheduleItems. The below code supplies a way for clients to create new ScheduleItems, and find existing ones using the finders we specified previously. Note that ScheduleItems beans are not returned directly, but, rather their data is wrapped up in a ScheduleItemWrapper. The ScheduleItemWrapper will be created in the next step. Delete the existing 'foo' method and add the following methods to ScheduleSessionBean. You will have several compile errors which can be fixed using organized imports (Control-Shift-o); just be sure you select the correct types if there are multiple choices (javax.naming.Context, javax.rmi.PortableRemoteObject, ,java.util.List, java.util.Iterator)
    	/**
    	 * @ejb.interface-method view-type="both"
    	 */
    	public ScheduleItemWrapper addScheduleItem(String name, int startTime,
    			int endTime, int day, String scheduleID) {
    		ScheduleItemLocalHome home = getScheduleItemLocalHome();
    		try {
    			ScheduleItemLocal scheduleItem = home.create(name);
    			scheduleItem.setStartTime(startTime);
    			scheduleItem.setEndTime(endTime);
    			scheduleItem.setDay(day);
    			scheduleItem.setScheduleID(scheduleID);
    			return new ScheduleItemWrapper(name, startTime, endTime, day,
    					scheduleID);
    		} catch (CreateException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return null;
    	}
    
    	/**
    	 * @ejb.interface-method view-type="both"
    	 */
    	public List getScheduleItem(String name) {
    		ScheduleItemLocalHome home = getScheduleItemLocalHome();
    		try {
    			Collection items = home.findByName(name);
    			return wrapScheduleItemsInList(items);
    		} catch (FinderException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return null;
    	}
    
    	/**
    	 * @ejb.interface-method view-type="both"
    	 */
    	public List getAllScheduleItems() {
    		ScheduleItemLocalHome home = getScheduleItemLocalHome();
    		try {
    			Collection items = home.findAll();
    			return wrapScheduleItemsInList(items);
    		} catch (FinderException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return null;
    	}
    
    	/**
    	 * @ejb.interface-method view-type="both"
    	 */
    	public List getScheduleItemesForScheduleID(String scheduleID) {
    		ScheduleItemLocalHome home = getScheduleItemLocalHome();
    		try {
    			Collection items = home.findByScheduleID(scheduleID);
    			return wrapScheduleItemsInList(items);
    		} catch (FinderException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return null;
    	}
    	
    	private List wrapScheduleItemsInList(Collection items) {
    		Iterator iterator = items.iterator();
    		List list = new ArrayList(items.size());
    		while (iterator.hasNext()) {
    			ScheduleItemLocal scheduleItem = (ScheduleItemLocal) iterator
    					.next();
    			ScheduleItemWrapper wrapper = new ScheduleItemWrapper(scheduleItem
    					.getName(), scheduleItem.getStartTime(), scheduleItem
    					.getEndTime(), scheduleItem.getDay(), scheduleItem
    					.getScheduleID());
    			list.add(wrapper);
    		}
    		return list;
    	}
    
    	private ScheduleItemLocalHome getScheduleItemLocalHome() {
    		try {
    			Context context = new InitialContext();
    			Object obj = context.lookup("java:comp/env/ejb/ScheduleItemLocal");
    			ScheduleItemLocalHome home = (ScheduleItemLocalHome) PortableRemoteObject
    					.narrow(obj, ScheduleItemLocalHome.class);
    			return home;
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return null;
    	}
    
  3. Next, ScheduleItemWrapper needs to be created. Create a new JavaClass called ScheduleItemWrapper in the ejbs package. Be sure to add the java.io.Serializable interface.


  4. Next, open ScheduleItemWrapper in the Java editor and add the following fields.
    	public java.lang.String name;
    
    	public int starttime;
    
    	public int endtime;
    
    	public int day;
    
    	public java.lang.String scheduleId;
    	
  5. Right click on ScheduleItemWrapper in the source editor and select Source -> Generate Getters and Setters. Generate a getter and setter for each field.




  6. Finally, add the following constructor.
    	public ScheduleItemWrapper(java.lang.String name, int starttime,
    			int endtime, int day, java.lang.String scheduleId) {
    		this.name = name;
    		this.starttime = starttime;
    		this.endtime = endtime;
    		this.day = day;
    		this.scheduleId = scheduleId;
    	}
    	
Building a Web Client
 

The first step is to create a Web project.

 
  1. Select File -> New -> Project -> Web -> Dynamic Web Project


  2. Click Next and fill in 'ScheduleWeb' for the Web project name, expand the advanced section and select '2.3' for the module version, 'Generic JBoss 3.2.3' for server target, 'ScheduleEAR' for the EAR Application name, and check Add Support for annotated Java classes. Click finish.


  3. Expand the 'Dynamic Web Projects' node in the project explorer, and right click on ScheduleWeb and select 'Properties'.


  4. Select the 'Java JAR Dependencies' properties page, and then click the checkbox next to 'ScheduleEJB.jar' to add a module dependency to the EJB module.


Creating a Servlet
 

Now you will create a servlet which calls the ScheduleSessionBean.

 
  1. Select File -> New -> Other -> WEB -> Servlet and then click next. Fill in 'servlets' for the package, and 'ServletExample' for the Classname. Check 'Generate an annotated servlet class' and then click finish.


  2. Similar to the EJB reference from ScheduleSessionBean to ScheduleItemLocal, we are going to create a reference from ScheduleExample to ScheduleSessionLocal by entering the following XDoclet tags to the class level JavaDoc (right below the @web.servlet-mapping line in ScheduleExample).
     * @web.ejb-local-ref home="ejbs.ScheduleSessionLocalHome"
     *                    local="ejbs.ScheduleSessionLocal"
     *                    name="ejb/ScheduleSession" type="Session"
     *                    link="ScheduleSession"
     * 
     * @jboss.ejb-local-ref ref-name="ScheduleSession"
     *                      jndi-name="ejb/ejbs/ScheduleSessionHome"
    	
  3. Next, add the following methods to ScheduleExample to access ScheduleSessionBean. An organize imports will clean up the compile errors. Be sure to select the correct types (javax.nameing.Context and javax.rmi.PortableRemoteObject).
    	private ScheduleSessionLocalHome scheduleSessionLocalHome;
    
    	private ScheduleSessionLocal getScheduleSession() {
    		if (null == scheduleSessionLocalHome) {
    			try {
    				Context context = new InitialContext();
    				Object obj = context
    						.lookup("java:comp/env/ejb/ScheduleSession");
    				scheduleSessionLocalHome = (ScheduleSessionLocalHome) PortableRemoteObject
    						.narrow(obj, ScheduleSessionLocalHome.class);
    			} catch (NamingException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    		try {
    			return scheduleSessionLocalHome.create();
    		} catch (CreateException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		return null;
    	}
    	
  4. Next, fill the currently empty implementation of doPost() with the following code. An organize imports (select java.util.List) will clean up most of the errors.
    		response.setContentType("text/plain");
    		PrintWriter out = response.getWriter();
    
    		ScheduleSessionLocal scheduleSession = getScheduleSession();
    
    		String scheduleid = request.getParameter("multidayscheduleid");
    		if (scheduleid != null) {
    			String title = request.getParameter("title");
    			int starttime = Integer.parseInt(request.getParameter("starttime"));
    			int endtime = Integer.parseInt(request.getParameter("endtime"));
    			String[] days = request.getParameterValues("day");
    
    			if (days != null) {
    				for (int i = 0; i < days.length; i++) {
    					String dayString = days[i];
    					int day;
    					if (dayString.equalsIgnoreCase("SUN"))
    						day = 0;
    					else if (dayString.equalsIgnoreCase("MON"))
    						day = 1;
    					else if (dayString.equalsIgnoreCase("TUE"))
    						day = 2;
    					else if (dayString.equalsIgnoreCase("WED"))
    						day = 3;
    					else if (dayString.equalsIgnoreCase("THU"))
    						day = 4;
    					else if (dayString.equalsIgnoreCase("FRI"))
    						day = 5;
    					else
    						day = 6;
    
    					scheduleSession.addScheduleItem(title, starttime, endtime,
    							day, scheduleid);
    				}
    				request.getSession().setAttribute(
    						"schoolschedule",
    						scheduleSession
    								.getScheduleItemesForScheduleID(scheduleid));
    				getServletContext().getRequestDispatcher("/TestSchedule.jsp")
    						.forward(request, response);
    			}
    		}
    
    		String name = request.getParameter("nameGet");
    		if (name != null) {
    			List items = scheduleSession.getScheduleItem(name);
    			out.println("Schedule Item retrieved:");
    			printTable(out, items);
    			return;
    		}
    		String scheduleID = request.getParameter("scheduleID");
    		if (scheduleID != null) {
    			List items = scheduleSession
    					.getScheduleItemesForScheduleID(scheduleID);
    			out.println("ScheduleIDs matching " + scheduleID + ":");
    			printTable(out, items);
    			return;
    		}
    		List items = scheduleSession.getAllScheduleItems();
    		out.println("All Schedule Items:");
    		printTable(out, items);
    		return;
    	
  5. Lastly, add the missing printTable() method and perform an organized imports.
    	private void printTable(PrintWriter out, List items) {
    		out.println("<TABLE border=\"1\" cellspacing=\"0\"><TBODY><TR>");
    		out.println("<TH align=\"center\" valign=\"middle\">Name</TH>");
    		out.println("<TH align=\"center\" valign=\"middle\">StartTime</TH>");
    		out.println("<TH align=\"center\" valign=\"middle\">EndTime</TH>");
    		out.println("<TH align=\"center\" valign=\"middle\">Day</TH>");
    		out.println("<TH align=\"center\" valign=\"middle\">ScheduleID</TH></TR>");
    		for (int i = 0; i < items.size(); i++) {
    			ScheduleItemWrapper item = (ScheduleItemWrapper) items.get(i);
    			out.println("<TR>");
    			out.println("<TD>" + item.getName() + "</TD>");
    			out.println("<TD>" + item.getStarttime() + "</TD>");
    			out.println("<TD>" + item.getEndtime() + "</TD>");
    			out.println("<TD>" + item.getDay() + "</TD>");
    			out.println("<TD>" + item.getScheduleId() + "</TD>");
    			out.println("</TR>");
    		}
    		out.println("</TBODY></TABLE>");
    	}
    	
Creating A JSP
 

This is the final piece of this example schedule application, and works with ServletExample created above to provide a user interface.

 
  1. Select File -> New -> Other-> Web -> JSP and click next. Select the WebContent directory under ScheduleWeb, and fill in TestSchedule.jsp for the file name. Click finish.


  2. Open TestSchedule.jsp with the JSP Editor and add a meaninggul title where it says 'Insert title here', e.g. 'Schedule Example'.
  3. In order to use the standard tag libraries you will first have to download and install them into our project. Open your Web browser to http://jakarta.apache.org/taglibs/. Under JCP Standardized Tag Libraries on the left select Standar-1.1:JSTL 1.0(2.0) (Be sure you select 1.0 and not 1.1!). Scroll down to the Download section and select the first link, Download the Standard Tag Library Release from an Apache Jakara Project Mirror. Select Taglibs and then Library Releases. Select standard and then select to download jakarta-taglibs-standard-current.zip. Once the zip file download, open it and extract jstl.jar and standard.jar into the WebContent/WEB-INF/lib folder in your project. Select your project, right click on it and select Refresh. The libraries are automatically added to your Java classpath. There is currently a bug which hids the contents of the lib directory in the Project Explorer view, but if you switch to the Navigator view, your project should look like this:


  4. In order to use the tag libraries you have just downloaded you will have to declare them in your JSP. At the top of the JSP file (right above <!DOCTYPE HTML) add in the following line
    	<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>	
    	


  5. Finally, add the following code to within the body tags:
    <FORM action="/ScheduleWeb/ScheduleExample" method="post">Schedule<INPUT
    	type="text" name="multidayscheduleid" size="35"><BR>
    Course Name: <INPUT type="text" name="title" size="35"><BR>
    Course Time: Sun<INPUT type="checkbox" name="day" value="sun"> Mon<INPUT
    	type="checkbox" name="day" value="mon"> Tue<INPUT type="checkbox"
    	name="day" value="tue"> Wed<INPUT type="checkbox" name="day"
    	value="wed"> Thu<INPUT type="checkbox" name="day" value="thu"> Fri<INPUT
    	type="checkbox" name="day" value="fri"> Sat<INPUT type="checkbox"
    	name="day" value="sat"> <SELECT name="starttime">
    	<OPTION value="8">8:00am</OPTION>
    	<OPTION value="9">9:00am</OPTION>
    	<OPTION value="10">10:00am</OPTION>
    	<OPTION value="11">11:00am</OPTION>
    	<OPTION value="12">12:00pm</OPTION>
    	<OPTION value="13">1:00pm</OPTION>
    	<OPTION value="14">2:00pm</OPTION>
    	<OPTION value="15">3:00pm</OPTION>
    	<OPTION value="16">4:00pm</OPTION>
    	<OPTION value="17">5:00pm</OPTION>
    	<OPTION value="18">6:00pm</OPTION>
    	<OPTION value="19">7:00pm</OPTION>
    	<OPTION value="20">8:00pm</OPTION>
    	<OPTION value="21">9:00pm</OPTION>
    </SELECT> to <SELECT name="endtime">
    	<OPTION value="9">9:00am</OPTION>
    	<OPTION value="10">10:00am</OPTION>
    	<OPTION value="11">11:00am</OPTION>
    	<OPTION value="12">12:00pm</OPTION>
    	<OPTION value="13">1:00pm</OPTION>
    	<OPTION value="14">2:00pm</OPTION>
    	<OPTION value="15">3:00pm</OPTION>
    	<OPTION value="16">4:00pm</OPTION>
    	<OPTION value="17">5:00pm</OPTION>
    	<OPTION value="18">6:00pm</OPTION>
    	<OPTION value="19">7:00pm</OPTION>
    	<OPTION value="20">8:00pm</OPTION>
    	<OPTION value="21">9:00pm</OPTION>
    	<OPTION value="22">10:00pm</OPTION>
    </SELECT> <BR>
    <BR>
    <INPUT type="submit" name="Submit" value="AddCourse"></FORM>
    
    <TABLE border="1" cellspacing="0">
    	<TBODY>
    		<TR>
    			<TH align="center" valign="middle" width="80"></TH>
    			<TH align="center" valign="middle" width="100">Sunday</TH>
    			<TH align="center" valign="middle">Monday</TH>
    			<TH align="center" valign="middle">Tuesday</TH>
    			<TH align="center" valign="middle">Wednesday</TH>
    			<TH align="center" valign="middle">Thursday</TH>
    			<TH align="center" valign="middle">Friday</TH>
    			<TH align="center" valign="middle">Saturday</TH>
    		</TR>
    		<c:forEach begin="8" end="21" step="1" var="time">
    			<TR>
    				<TD align="center" valign="middle" width="80"><c:choose>
    					<c:when test="${time == 12}">
    						<c:out value="${time}" />:00pm
    </c:when>
    					<c:when test="${time > 12}">
    						<c:out value="${time - 12}" />:00pm
    </c:when>
    					<c:otherwise>
    						<c:out value="${time}" />:00am
    </c:otherwise>
    				</c:choose></TD>
    				<c:forEach begin="0" end="6" step="1" var="day">
    					<TD align="center" valign="middle" width="100"><c:forEach
    						items="${schoolschedule}" var="clazz">
    						<c:if
    							test="${clazz.starttime <= time
    && clazz.endtime > time
    && clazz.day == day}">
    							<c:out value="${clazz.name}" />
    						</c:if>
    					</c:forEach></TD>
    				</c:forEach>
    			</TR>
    		</c:forEach>
    	</TBODY>
    </TABLE>
    
    <FORM method="post" action="/ScheduleWeb/ScheduleExample">Schedule:<INPUT
    	type="text" name="scheduleID" size="20"><br>
    <INPUT type="submit" value="Get Schedule"></FORM>
    
    
    <FORM method="post" action="/ScheduleWeb/ScheduleExample">Course Name:<INPUT
    	type="text" name="nameGet" size="20"><br>
    <INPUT type="submit" value="Find Schedules"></FORM>
    
    
    <FORM method="post" action="/ScheduleWeb/ScheduleExample"><INPUT
    	type="submit" value="Get All Schedules"></FORM>	
    	
Running And Testing The School Schedule Web Application
 

Your school schedule application is now complete. Now it is time to take it for a spin.

 
  1. Right click on the servers view and select New -> Server.



  2. Select 'Generic JBoss 3.2.3' under Generic Examples and click Finish.



  3. Right click on the newly created server in the Servers view and select run. Wait a few seconds to ensure the server started up correctly. The Console view should look something like this:



  4. Flip back to the servers view. Right click on the new running server and select 'Add and Remove Projects...' which will bring up the dialog below. Select ScheduleEAR from the left panel and click 'Add >' to add it to the right panel as shown below. Click Finish.



  5. Wait a few more seconds while the project is added to the server and started. Once it is finished, the Console view should look like this:



  6. Now, back in the Project Explorer right click on 'TestSchedule.jsp' and select 'Run As' -> 'Run on Server'. This will bring up the below dialog. Click Finish.



  7. An embedded web browser should open showing the following page.



  8. The 'Schedule' field (backed by scheduleID in the CMP) differentiates one schedule from another (e.g. John's schedule from Mary's schedule). Hopefully, the rest is straight forward enough.

    The fields below the calendar use the various finder methods we defined on th CMP. Below are a few examples. The first is after a few courses were added to 'John's Schedule'



  9. Next is the result of clicking 'Get Schedule' for 'John's Schedule'



  10. Next is the result of clicking 'Find Schedules' for 'Math'



  11. Finally, here is the result of clicking 'Get All Schedules'.



  12. Experiment adding more courses into your schedule.
Summary
 

In this tutorial you learned how to configure Eclipse to work with JBoss and create J2EE EJB and Web projects that uses a CMP Bean, a Session Bean, a servlet, and a JSP to create a student class schedule J2EE Web application. This application, while simple, provides a good introduction to Java Web development and some of the Web development tools available in the Eclipse Web Tools Platform project.