Question: Assignment One First Web Application Tis application is designed as an introduction to developing a simple web application. The source needed for each file is

Assignment One

First Web Application

Tis application is designed as an introduction to developing a simple web application. The source needed for each file is in the following pages. Perform the following:

  1. Create a web application.
  2. Create the appropriate JAVA, HTML, JSP, and CSS files. Copy the following source into those files.

When complete, zip the project folder and submit to Canvas.

This assignment is worth 20 points.

index.html

CIS640 Assignment 1

Join our email list

To join our email list, enter your name and

email address below.

Email:

First Name:

Last Name:

web.xml

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee

http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

EmailListServlet

servlets.EmailListServlet

EmailListServlet

/emailList

index.html

index.jsp

main.css

/* The styles for the elements */

body {

font-family: Arial, Helvetica, sans-serif;

font-size: 85%;

margin-left: 2em;

margin-right: 2em;

width: 400px;

}

h1 {

font-size: 140%;

color: teal;

margin-bottom: .5em;

}

h2 {

font-size: 120%;

color: teal;

margin-bottom: .5em;

}

label {

float: left;

width: 7em;

margin-bottom: 0.5em;

font-weight: bold;

}

input[type="text"], input[type="email"] { /* An attribute selector */

width: 15em;

margin-left: 0.5em;

margin-bottom: 0.5em;

}

span {

margin-left: 0.5em;

margin-bottom: 0.5em;

}

br {

clear: both;

}

/* The styles for the classes */

.pad_top {

padding-top: 0.25em;

}

.margin_left {

margin-left: 0.5em;

}

/* The styles for the tables */

table {

border: 1px solid black;

border-collapse: collapse;

width: 50em;

}

th, td {

border: 1px solid black;

text-align: left;

padding: .5em;

}

.right {

text-align: right;

}

EmailListServlet.java

package servlets;

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import business.User;

import database.UserDB;

public class EmailListServlet extends HttpServlet {

protected void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

String url = "/index.html";

// get current action

String action = request.getParameter("action");

if (action == null) {

action = "join"; // default action

}

// perform action and set URL to appropriate page

if (action.equals("join")) {

url = "/index.html"; // the "join" page

}

else if (action.equals("add")) {

// get parameters from the request

String firstName = request.getParameter("firstName");

String lastName = request.getParameter("lastName");

String email = request.getParameter("email");

// store data in User object and save User object in database

User user = new User(firstName, lastName, email);

User.insert(user);

// set User object in request object and set URL

request.setAttribute("user", user);

url = "/thanks.jsp"; // the "thanks" page

}

// forward request and response objects to specified URL

getServletContext()

.getRequestDispatcher(url)

.forward(request, response);

}

protected void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

doPost(request, response);

}

}

User.java

package business;

import java.io.Serializable;

public class User implements Serializable {

private String firstName;

private String lastName;

private String email;

public User() {

firstName = "";

lastName = "";

email = "";

}

public User(String firstName, String lastName, String email) {

this.firstName = firstName;

this.lastName = lastName;

this.email = email;

}

public String getFirstName() {

return firstName;

}

public static long insert(User user) {

return UserDB.insert(user);

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

}

UserDB.java

package database;

import business.User;

public class UserDB {

public static long insert(User user) {

// TODO: Add code that adds the user to the database

return 0;

}

}

thanks.jsp

<%@page contentType="text/html" pageEncoding="utf-8"%>

CIS640 Assignment 1

Thanks for joining our email list

Here is the information that you entered:

Email:

${user.email}

First Name:

${user.firstName}

Last Name:

${user.lastName}

To enter another email address, click on the Back

button in your browser or the Return button shown

below.

What extra information is required?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!