Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CSCI 5895: Advanced Java Programming for E-Commerce Assignment 3: JSP and JavaBeans Due Oct. 29 Introduction You are to the “appointment book” servlets that you developed for Assignment 2 to use Java Server Pages instead. In addition, you will develop a session bean which controls access to the “appointment book” object, and the database used to store it. The external requirements for the set of pages is identical to that in Assignment 2: The user first goes to a page at (http://localhost:8080/hw2/Form) that lists available times (as the result of a database query). The user selects a time, and is taken to a page (at http://localhost:8080/hw2/Name) where they enter their name. The name is entered into the AppointmentBook Access database and a confirmation message is printed. The only difference is the architecture of the pages – all interaction with the client is to be done with Java Server Pages, and all interaction with the database is to be done with an AppointmentBean class. Architecture Your overall architecture should be based on the following model: AppointmentForm.jsp CLIENT web. xml AppointmentName.jsp AppointmentReply.jsp JSP Exception Page(s) getTimes setTime AppointmentBean setName getTime AppointmentBook database As before, all access to the Java Server Pages is to be through aliased names in the web.xml deployment descriptor. The role of the server pages, the exception pages, and the AppointmentBean is described below. The AppointmentBean Bean The AppointmentBean controls all information and database access related to the appointment book, providing get/set methods that will be called by the JSP pages. Those methods will be something like the following: public String[] getTimes() This method opens the database, executes a query to find all OPEN times, and returns an array (built from the ResultSet) containing all of those times. This method will presumably be called by the Form JSP page. The Java code on the page will then iterate through the array to create the list of available times, each with a radio button. Note that having this return an array of Strings is not necessarily the best approach, just possibly the simplest. You might also consider the following approaches: Building and returning an Enumeration object (check the Sun web site for more information on this). Defining a custom iterator tag to simplify processing the list of times. Sufficiently sophisticated solutions may receive extra credit. Also note that the one approach that you are not allowed to use is to have your bean generate any actual HTML – that should only be done by the JSP pages themselves. public void setTime(String) This method passes the time selected by the user to the bean, for storage. This method will presumably be called by the Name JSP page, which is called when the user selects a time on the Form page. public void setName(String) This method passes the time selected by the user to the bean. The bean should then store the name into the database, at the time previously set by the setTime method. This method will presumably be called by the Reply JSP page, which is called when the user enters a name on the Name page. public String getTime() This method returns the time previously set by the setTime method. This method will presumably be called by the Reply JSP page, in order to print the final confirmation of the appointment. Note that you are allowed to define any other bean methods that you think might be useful, as long as you follow the get/set syntax. Other notes about the bean: Note that it must be created as a session bean. It is to be stored in a package called com.ysu. This means that you will need to set up the appropriate directory structure (more on this below). Java Server Page Format To simplify maintenance, you are required to use tags instead of Java code wherever possible on your pages. You will probably need to use some actual Java on your Form page, in order to process the array of times returned by the getTimes method. However, you should be able to implement the Name and Reply pages using only jsp:getProperty and jsp:setProperty tags. Error Handling As before, your pages should be able to handle problems by either displaying messages or forwarding to other pages. Specifically: If there are no appointment times available, a message should be displayed instead of a list, and the user should not be able to proceed any further. If the user attempts to skip stages in the process – specifically, if they attempt to make the appointment before selecting a time – they should be forwarded to the initial Form page. If any other problem occurs (such as losing the database connection, etc.), a generic error page should be displayed instead of the Tomcat exception page. All of these things can be done using exception pages (you can use one page or several). Consider having your bean throw Exception objects, which the JSP pages will forward to an exception page (or pages) that display messages or forward to other pages. Other Notes As with any other program you write, your pages and bean must be well documented. Extra credit may be given for pages and beans that are particularly well designed, have particularly nice output, or handle potential problems beyond those described in the requirements. What to Turn In You are to turn in a diskette with your entire hw3 directory, including all Java Server Pages, class files (in the appropriate directory), and the web.xml file needed to reference them. Specifically, your diskette should have the following directory structure: WEB-INF a: hw3 .jsp pages classes web.xml com ysu AppointmentBean.class AppointmentBean.java You are also to turn in hardcopies of the source code for each of your pages and classes.