Santa Monica College Course Outline For COMPUTER SCIENCE 83, Server-Side Java Web Programming Course Title: Server-Side Java Web Programming Units: 3.00 Total Instructional Hours (usually 18 per unit): 90 Hours per week (full semester equivalent) in 5.00 In-Class Lab: 0 Arranged: Lecture: Date Submitted: May 2011 Date Updated: Transferability: Transfers to CSU IGETC Area: CSU GE Area: SMC GE Area: Degree Applicability: Prerequisite(s): CS 55 and CS 81 Pre/Corequisite(s): None Corequisite(s): None Skills Advisory(s): None I. Catalog Description This course teaches how to design and write applications that extend Web servers. These applications process data submitted from Web forms and access backend databases to dynamically generate Web pages. This course covers the Java Servlets and JavaServer Pages (JSP) server-side technologies. Examples of Appropriate Text or Other Required Reading: (include all publication II. dates; for transferable courses at least one text should have been published within the last five years) 1. Murach's Java Servlets and JSPs, 2nd, Andrea Steelman and Joel Murach, Mike Murach & Associates, Inc 2007 2. Core Servlets and JavaServer Pages, 2nd, Marty Hall, Sun Microsystems Press/Prentice Hall PTR 2006 III. Course Objectives Upon completion of this course, the student will be able to: 1. Define and use Java Servlets and JavaServer Pages (JSP) 2. Write server-side programs in the Java language 3. Process data from online forms
4. Define and use cookies, redirection, applications, and sessions 5. Develop JSP applications 6. Demonstrate basic server-side database access using both Java Servlets and JSP IV. Methods of Presentation: Discussion, Lecture and Discussion, Other (Specify) Other Methods: Lecture and discussion solving Web server related problems from original statement to solution, demonstration and analysis of existing problem solutions through flowcharting and tracing, and discussion of the strengths and weaknesses of different algorithms. V. Course Content % of course Topic 7% Introduction to Web programming 7% Installing and using Tomcat 6% Developing JavaServer Pages 7% Developing Servlets 7% Sessions and Cookies 6% Creating and Using JavaBeans 7% Working with custom JSP tags 7% Using MySQL 6% Using Java with databases 7% Using Java Mail 7% SSL 6% Restricting access to a web resource 7% Working with XML 7% Enterprise JavaBeans 6% Shopping Cart application 100% Total VI. Methods of Evaluation: (Actual point distribution will vary from instructor to instructor but approximate values are shown.)
Percentage Evaluation Method 20 % Projects 30 % Homework 30 % Midterm exams 20 % Final exam 100 % Total VII. Sample Assignments: Sample 1 Program #2 The goal of this assignment is to practice writing HTML front-ends and servlets. When you complete this program, please upload your HTML and Java source files along with your web.xml configuration file, as I don't need your whole Eclipse Tomcat project. Step 1: Create And Deploy The program1.classes.firstservlet Class Follow the steps outlined in the Program1Servlet tutorial available by clicking here. Once you complete this step, you will have a working servlet that responds to HTTP GET commands. Step 2: Extend The program1.classes.firstservlet Class Following the dopost signature described in class, enhance your servlet so that it also knows how to respond to POST requests. The additional method you need to write has the signature: public void dopost( HttpRequest request, HttpResponse response ) throws ServletException, IOException; Like the doget(... ), have this method just bark back a "Hello World!" message. Step 2: Create An HTML Page For this assignment, I would like you to create the HTML page shown below. While all of the controls should be live and enabled, the servlet we will connect them to will not at all verify the user data entry or even process the request in any meaningful fashion. This whole assignment is practicing the skills we need to make more complex applications. Desired HTML Page HTML Authoring needs to become a fairly precise science. Each of the controls needs to be carefully named, as that name will wind up appearing in the java servlet code that processes the request. To get you into the swing of things, please name the control so that it matches the name of the data it is prompting for. I'll be looking for the control names of Name, Address, Flavor, Mood and Age. And yes, the java servlet code will be case-sensitive. You are certainly free to create additional tags and controls, if you choose.
Step 3: Wire Your Buttons To The HelloWorldServlet Finally, I'd like you to connect all of your buttons to the FirstServlet. Please have buttons that work with both POST and GET methods, as I'd like you to see the difference between these approaches. The actual url to connect to will depend on the context name you supplied to Eclipse when you built the HelloWorldServlet. If you followed the initial directions, the diagram below should match your world. The correct url to use to talk to your servlet will be: http://localhost:8080/program1/first HttpServlet /_\ FirstServlet FirstServlet extends HttpServlet public void doget( HttpRequest request, HttpResponse response ) throws ServletException, IOException; public void dopost( HttpRequest request, HttpResponse response ) throws ServletException, IOException; Sample 2 Program #5 The goal of this assignment is to practice using JSP and JSTL with forms and the Derby API I made for you to pull information into and out of the database. You will be asked to make a number of HTML pages. As there are many moving parts involved, please take small steps to the goal. In return for extra credit, you are free to embellish the project as much as you like. I would like you to try using the JSTL Action and JSTL SQL Action tags... Project 1: AdminApp
Step 1: Create HTML Pages Create the HTML pages shown below. Usually customers don't enter their own product prices, so it's not very realistic. But this will give us a sandbox in which to work thru some of the other ideas we have seen in class. As we learn more and more in this course, we will be able to revise and create much more realistic scenarios for this application. Pay careful attention to the names of your form fields as these names will wind up as member names of the Java Beans you create. Desired HTML Pages Supporting Database Tables (Partial) Users Table User_ID Username Password 1 scott tiger 2 howard stahl 3 muffin doggie (Partial) Customers Table Cust_ID Name Phone Address City State 6 Barry Manilow 310-123-4570 84 Mega Hits Road Palm Springs California 2 Muffin Stahl 310-545-4545 1 Poodle Lane Apricot California
(Partial) Orders Table Order_ID Date Cust_ID Amount Description 14 2004-10-01 6 45.50 1 New Hit Record 2 2004-10-02 2 29.95 Science Diet Dog Food Step 2: Create The Login Servlet Create a servlet that will correctly "bean up" the login data you specified in the HTML page. Validate the data entered, ensuring that the user supplied something for each field. If you follow the design approach discussed in class, that validation will be a bean method, rather than buried in the HttpServlet subclass that you create in this step. Have your servlet forward the request to continue the application flow below or forward to a failure page with a link back to the offensive form, depending on whether the user did wrong. --------------- HttpServlet --------------- /_\ LoginServlet LoginServlet extends HttpServlet public void dopost( HttpRequest request, HttpResponse response ) throws ServletException, IOException; Step 3: Create The JSTL JSP Pages Because I think it might work out kinda fun, I'd like you to get the buttons on the Admin Page wired to a JSTL JSP page. You are free to use beans or not, use servlets or not. But I'd like you using the JSTL Actions and/or SQL Actions we discussed in
class. If you wind up trying out the JSTL SQL Actions, then you probably won't need to use the DBQuery class I made for you earlier. But if you do, remember that the JSTL Actions work fine when banging against an Iterator, so you should be able to connect the JSTL Actions to the results of the DBQuery methods. Supporting Database Classes cs83.dbs.classes.dbquery static Iterator getallcustomers( ); static Customer getcustomerbyid( Integer id ); static void insertcustomer( Customer c ); static Iterator getallorders( ); static Order getorderbyid( Integer id ); static void insertorder( Order o ); static User getuserbyusername( String username ); Helpful Java Interfaces java.util.iterator boolean hasnext( ); Object next( ); Step 4: Deploy Your Servlet In order to run your servlet, you will need to create a web.xml which registers your servlet with Tomcat. If you have followed my advice, you should be able to use the following file. Copy and paste what you see below into web.xml. Recall that web.xml belongs in your webapp's /WEB-INF folder. I think everything will match my pictures if you give your project a context name of /Proj5. <web-app xmlns="http://www.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd" version="2.4" > <servlet> <servlet-name>project5loginservlet</servlet-name> <servlet-class>cs83.project5.loginservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>project5loginservlet</servlet-name> <url-pattern>/loginservlet</url-pattern> </servlet-mapping> </web-app> VIII. - Student Learning Outcomes