<%-- Document : index Created on : Jul 12, 2011, 11:55:58 AM Author : ztron --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Join our email list</title> </head> <h1>Join our email list</h1> <p>To join our email list, enter your name and email address below.<br/> Then, click on the Submit button.</p> <body> <form action="display_email_entry.jsp" method="get"> <table cellspacing="5" border="0"> <tr> <td align="right">First name:</td> <td><input type="text" name="firstName"></input></td> </tr> <tr> <td align="right">Last Name:</td> <td><input type="text" name="lastName"></input></td> </tr> <tr> <td align="right">Email address:</td> <td><input type="text" name="emailAddress"></input></td> </tr> <tr> <td></td> <td><br /><input type="submit" value="Submit"></input></td> </tr> </table> </form> </body> </html>
<%-- Document : display_email_entry Created on : Jul 12, 2011, 12:29:05 PM Author : ztron --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Email list</title> </head> <body> <%@page import="business.*, data.*" %> <% //get parameters from the request String firstName = request.getParameter("firstName"); String lastName = request.getParameter("lastName"); String emailAddress = request.getParameter("emailAddress"); //get the real path for the EmailList.txt file ServletContext sc = this.getServletContext(); String path = sc.getRealPath("/WEB-INF/EmailList.txt"); //use regular Java Objects User user = new User(firstName, lastName, emailAddress); UserIO.add(user, path); %> <h1>Thanks for joining our email list.</h1> <p>Here is the information that you entered.</p> <table cellpadding="5" cellspacing="5" border="1"> <tr> <td align="right">First Name:</td> <td><%= user.getFirstName() %></td> </tr> <tr> <td align="right">Last Name:</td> <td><%= user.getLastName() %></td> </tr> <tr> <td align="right">Email Address</td> <td><%= user.getEmailAddress() %></td> </tr> </table> <p>To enter another email address, click on the Back<br></br></p> <form action="index.jsp" method="get"> <input type="submit" value="Return" /> </form> </body> </html>
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package data; import java.io.*; import business.*; public class UserIO { public static void add(User user, String filepath)throws IOException { File file = new File(filepath); PrintWriter out = new PrintWriter(new FileWriter(file, true)); out.println(user.getEmailAddress()+ "|" + user.getFirstName()+"|" +user.getLastName()); out.close(); } }
package business; public class User { private String firstName; private String lastName; private String emailAddress; public User() { firstName = ""; lastName = ""; emailAddress = ""; } public User(String firstName, String lastName, String emailAddress) { this.firstName = firstName; this.lastName = lastName; this.emailAddress = emailAddress; } public void setFirstName(String firstName) { this.firstName = firstName; } public void setLastName(String lastName) { this.lastName = lastName; } public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } public String getLastName() { return lastName; } public String getEmailAddress() { return emailAddress; } public String getFirstName() { return firstName; } }
I don't see any error message.