/** ***************************************************************** ChooseAbs.java ICECCS 2001 Abstract choice @author Jeff Offutt @version 3.0 (01/26/01) This version expects the to address to be sent over as a parameter from the HTML. It's stored in a hidden field in the HTML file. This is more flexible: the addressee can be controlled from the server side. ********************************************************************* */ // Import Servlet Libraries import javax.servlet.*; import javax.servlet.http.*; // Import Java Libraries import java.io.*; import java.util.*; import java.lang.*; // Import SMTP Class import sun.net.smtp.SmtpClient; // ChooseAbs class // // CONSTRUCTOR: no constructor specified (default) // // **************** PUBLIC OPERATIONS ********************************* // void doPost () --> Main method for gathering data and sending email // void doGet () --> Not implemented. // void getParameters() --> Copies data into a StringBuffer. // Puts in global String message // boolean SendMail () --> Sends the message through email // void PrintHead () --> Prints the head of an HTML page //*********************************************************************** // // The possible IOException on the PrintWriter is thrown up. public class ChooseAbs extends HttpServlet { String msgFrom, msgTo, msgSubject; /** ***************************************************** * Overrides HttpServlet's doPost(). ********************************************************* */ public void doPost (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String message; res.setContentType ("TEXT/HTML"); PrintWriter out = res.getWriter (); message = getParameters (req); PrintHead (out); if (!sendMail (message)) { out.println ("An error occurred while attempting to access the mail server."); return; } // Send ack out.println ("Your selections have been submitted.
"); out.println ("Thank you!

"); out.println ("Sten and Jeff"); out.println (""); out.println (""); out.close (); } /** ***************************************************** * Gets the parameters. * Puts them in a string buffer. ********************************************************* */ private String getParameters (HttpServletRequest req) throws ServletException, IOException { StringBuffer tempStringBuffer = new StringBuffer (1024); msgSubject = "Abstract review choices"; // msgTo = "offutt@ise.gmu.edu"; // testing // msgTo = "offutt@ise.gmu.edu,sten.andler@ida.his.se"; // original // Who gets the data is a hidden field in the HTML. msgTo = req.getParameter ("MAILTO"); msgFrom = req.getParameter ("EMAIL"); tempStringBuffer.append ("From:: "); tempStringBuffer.append (req.getParameter ("NAME")); tempStringBuffer.append ("\n"); tempStringBuffer.append (" "); tempStringBuffer.append (req.getParameter ("EMAIL")); tempStringBuffer.append ("\n\n"); //I am not sure how to get the check boxes ... tempStringBuffer.append ("Choices: "); tempStringBuffer.append (req.getParameter ("review")); tempStringBuffer.append ("\n\n"); tempStringBuffer.append ("Conflicts: "); tempStringBuffer.append (req.getParameter ("conflict")); //message = tempStringBuffer.toString(); return (tempStringBuffer.toString()); } /** ***************************************************** * Sends the information through email. ********************************************************* */ private boolean sendMail (String Mes) { PrintStream out; SmtpClient send; try { send = new SmtpClient ("ise.gmu.edu"); send.from (msgFrom); send.to (msgTo); out = send.startMessage (); out.println ("From: " + msgFrom); out.println ("To: " + msgTo); out.println ("Subject: " + msgSubject); out.println ("\n----------------------------------\n"); out.println (Mes); out.println ("\r\n"); out.println ("\n----------------------------------"); out.flush (); out.close (); send.closeServer(); } catch (IOException e) { log ("Error occurred while sending mail", e); return false; } return true; } /** ***************************************************** * Prints the head of the HTML page, without the form. ********************************************************* */ private void PrintHead (PrintWriter out) throws IOException { out.println (""); out.println (""); out.println (" ICECCS 2001: Abstracts Ack"); out.println (""); out.println (""); out.println ("

ICECCS 2001: Abstracts Acknowledgement

"); out.println ("
"); } } // End ChooseAbs