/*
*
Main Entry Point J204 Java API Test Servlet
*/
package registration;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.math.*;
import java.net.*;
import java.io.*;
import java.sql.*;
import sun.net.smtp.*;
/**
* Servlet Registration
application
*
* @author Mark Larocca
* @version 1.00 10/07/2004
*
* Simple servlet
to register users on the Web
*
* This project requires
to have Tomcat and ANT installed.
*
*/
public final class reg
extends HttpServlet {
Connection jdbcConnect
= null;
public String s;
public String CompanyIn;
public String ExtensionIn;
public String CommentsIn;
public String SalutationIn;
public String FirstNameIn;
public String LastNameIn;
public String AddressIn;
public String Line2In;
public String Line3In;
public String CityIn;
public String StateIn;
public String ZipcodeIn;
public String CountryIn;
public String EmailIn;
public String PhoneIn;
public String MorningIn;
public String AfternoonIn;
public String FaxIn;
public String TitleIn;
public String HarborsideHotelIn;
public String ReceptionIn;
public String AttendingDateIn;
public String TrainingSessionIn;
public String RefresherIn;
public String PartyIn;
public String MondayIn;
public String TuesdayIn;
public String WednesdayIn;
public String TrackerIn;
public HttpSession
session;
public String strHTTPRedirectTo
= new String("https://insight.cca-int.com/registration/register05.html");
public void
doGet( HttpServletRequest request,
HttpServletResponse
response )
throws ServletException, IOException
{
// This method receives and responds to any GET request.
PrintWriter output;
response.setContentType( "text/html" ); // content
type
output = response.getWriter(); // get writer
// create and send HTML page to client
StringBuffer buf = new StringBuffer();
buf.append( "<HTML><HEAD>\n" );
buf.append( "<META http-equiv=refresh" );
buf.append( " content='1;URL=" + strHTTPRedirectTo
+ "'>\n" );
buf.append( "<TITLE>\n" );
buf.append( "Insight 2005 Registration\n" );
buf.append( "</TITLE></HEAD>\n"
);
buf.append( "</HTML>\n");
output.println( buf.toString() );
output.close(); // close PrintWriter stream
}
public void doPost(
HttpServletRequest request,
HttpServletResponse
response )
throws ServletException, IOException
{
// This method receives and responds to any POST request.
PrintWriter output;
response.setContentType( "text/html" ); // content
type
StringBuffer buf = new StringBuffer();
output = response.getWriter(); // get writer
// read current page
response
CompanyIn = request.getParameter(
"Company" );
SalutationIn = request.getParameter( "Salutation"
);
FirstNameIn = request.getParameter( "FirstName"
);
LastNameIn = request.getParameter( "LastName"
);
AddressIn = request.getParameter( "Address"
);
Line2In = request.getParameter( "Line2" );
Line3In = request.getParameter( "Line3" );
CityIn = request.getParameter( "City" );
StateIn = request.getParameter( "State" );
ZipcodeIn = request.getParameter( "Zipcode"
);
CountryIn = request.getParameter( "Country"
);
PhoneIn = request.getParameter( "Phone" );
ExtensionIn = request.getParameter( "Extension"
);
FaxIn = request.getParameter( "Fax" );
EmailIn = request.getParameter( "Email" );
MorningIn = request.getParameter( "Morning"
);
AfternoonIn = request.getParameter( "Afternoon"
);
CommentsIn = request.getParameter( "Comments"
);
TitleIn = request.getParameter( "Title" );
HarborsideHotelIn = request.getParameter( "harborsidehotel"
);
ReceptionIn = request.getParameter( "reception"
);
MondayIn = request.getParameter( "Monday"
);
TuesdayIn = request.getParameter( "Tuesday"
);
WednesdayIn = request.getParameter( "Wednesday"
);
if (MondayIn == null) {MondayIn = " ";}
if (TuesdayIn == null) {TuesdayIn = " ";}
if (WednesdayIn == null) {WednesdayIn = " ";}
AttendingDateIn = MondayIn + ", " + TuesdayIn
+ ", " + WednesdayIn;
TrainingSessionIn = request.getParameter( "trainingsession"
);
RefresherIn = request.getParameter( "refresher"
);
PartyIn = request.getParameter( "party" );
CompanyIn.trim();
SalutationIn.trim();
FirstNameIn.trim();
LastNameIn.trim();
AddressIn.trim();
Line2In.trim();
Line3In.trim();
CityIn.trim();
StateIn.trim();
ZipcodeIn.trim();
PhoneIn.trim();
ExtensionIn.trim();
FaxIn.trim();
EmailIn.trim();
CommentsIn.trim();
TitleIn.trim();
if (MorningIn == null) {MorningIn = " ";}
if (AfternoonIn == null) {AfternoonIn = " ";}
if (HarborsideHotelIn == null) {HarborsideHotelIn =
" ";}
if (ReceptionIn == null) {ReceptionIn = " ";}
if (AttendingDateIn == null) {AttendingDateIn = "
";}
if (TrainingSessionIn == null) {TrainingSessionIn =
" ";}
if (RefresherIn == null) {RefresherIn = " ";}
if (PartyIn == null) {PartyIn = " ";}
// Check to see
if customer already registered
// If so, a session will already exist
session = request.getSession(true);
if ((!session.isNew()) && (TrackerIn == session.getAttribute("tracker.name")))
{
// this session already registered
response.sendRedirect(strHTTPRedirectTo);
output.close(); // close PrintWriter stream
return;
}
TrackerIn = FirstNameIn + " " + LastNameIn;
session.setAttribute("tracker.name", TrackerIn);
String valueDsn = "com.cca.j204.J204Driver";
String valueConn = "JDBC:J204://ccamvs1:2455/SQL/admin/admin";
// create and send HTML page to client
buf.append( "<HTML><HEAD>\n<TITLE>\n"
);
buf.append( "Insight 2005 Registration\n" );
buf.append( "</TITLE></HEAD>\n<BODY><FORM
METHOD='GET'>\n" );
buf.append( "<H1> Insight 2005 Registration
</H1>" );
Random generator
= new Random (System.currentTimeMillis());
int i = generator.nextInt();
if (i < 0)
i = i * -1;
s = Integer.toString(i);
while (s.length() < 10)
s = "0" + s;
if (loadDriver(valueDsn,
buf)) // if driver loaded
{
if(doConnect(valueConn, buf)) // if connection valid
{
// execute SQL request
execInsert(buf);
shutDownServlet(buf);
}
}
buf.append( "</FORM></BODY></HTML>"
);
output.println( buf.toString() );
output.close(); // close PrintWriter stream
}
public void shutDownServlet(StringBuffer
buf)
{
try {
jdbcConnect.close();
jdbcConnect = null;
}
catch ( SQLException eSQL ) {
buf.append( "<br>
Dissconnect error: " + eSQL.getMessage() );
buf.append( "<br>
Your registration may be complete. \n" );
buf.append( "<br>
See previous messages. \n" );
}
}
protected boolean loadDriver(String szDriver, StringBuffer
buf)
{
boolean bRet = true;
try {
Class.forName(szDriver);
} catch(ClassNotFoundException
eClass)
{
bRet
= false;
buf.append("<br>Class
Not Found Error: <b>" + eClass.getMessage()
+ " </b>While Trying to Load Class: <b>"
+ szDriver + "</b> \n");
session.invalidate();
// erase session
}
return(bRet);
}
protected boolean doConnect(String szConnect, StringBuffer
buf)
{
boolean bRet
= true;
if(szConnect
!= null)
{
try
{
jdbcConnect
= DriverManager.getConnection(szConnect);
}
catch(SQLException
eSQL)
{
buf.append("<br>Connection error:
<b>" + eSQL.getMessage() + "</b>
Connect String: <b>" + szConnect + "</b>
\n");
buf.append( "<br>Please try again
later, or Call CCA Support \n" );
jdbcConnect = null;
bRet = false;
session.invalidate(); // erase session
}
}
return(bRet);
}
protected void emailReply(StringBuffer buf)
{
try {
SmtpClient mailer
= new SmtpClient("xyz.yourcompany.com");
mailer.from("xyz@yourcompany.com");
mailer.to(EmailIn);
java.io.PrintStream ps = mailer.startMessage();
ps.println("From: " + "xyz@yourcompany.com");
ps.println("To: " + EmailIn);
ps.println("Subject: " + "Insight 2005
Registration");
ps.println("\n Thank you for registering for CCA's
Insight 204 Symposium");
ps.println("\n being held in Boston, MA., June
5-8,2005.");
ps.println("\n Your Registration ID number is "
+ s + ".");
ps.println("\n If you have any questions or need
to make changes, please contact");
ps.println("\n Cheryl Hanlin at (508) 270-6666,
ext 567.");
ps.println("\n We look forward to seeing you in
Boston in June!");
mailer.closeServer();
mailer = new SmtpClient("xyz.yourcompany.com");
mailer.from(EmailIn);
mailer.to("xyz@yourcompany.com");
ps = mailer.startMessage();
String Body = "\n";;
ps.println("From: " + EmailIn);
ps.println("To:
" + "xyz@yourcompany.com");
ps.println("Subject:
" + "Insight 2005 Registration");
Body = Body + "\nCompany: \t" + CompanyIn;
Body = Body + "\nName: \t" + SalutationIn
+ " " + FirstNameIn + " " + LastNameIn;
Body = Body + "\nAddress: \t" + AddressIn;
Body = Body + "\n \t" + Line2In;
Body = Body + "\n \t" + Line3In;
Body = Body + "\n \t" + CityIn + ", "
+ StateIn + " " + ZipcodeIn;
Body = Body + "\nCountry: \t" + CountryIn;
Body = Body + "\nEmail: \t" + EmailIn;
Body = Body + "\nPhone: \t" + PhoneIn + "
Ext: " + ExtensionIn;
Body = Body + "\nFax: \t" + FaxIn;
Body = Body + "\nTitle: \t" + TitleIn;
Body = Body + "\nHarborside Hotel: \t" + HarborsideHotelIn;
Body = Body + "\nReception: \t" + ReceptionIn;
Body = Body + "\nAttending Dates:\t" + AttendingDateIn;
Body = Body + "\nDinner Party: \t" + PartyIn;
Body = Body + "\nTraining Session:\t" + TrainingSessionIn;
Body = Body + "\nRefresher course: \t" + RefresherIn;
Body = Body + "\nMorning Class: \t" + MorningIn;
Body = Body + "\nAfternoon Class:\t" + AfternoonIn;
Body = Body + "\nComments:";
Body = Body + "\n\t" + CommentsIn;
ps.println(Body);
mailer.closeServer();
}
catch (Exception ex) {
buf.append( "<br>There was an error sending
your email response! \n" );
buf.append( "<br>Please Call CCA Support. \n"
);
}
}
protected void execInsert(StringBuffer buf)
{
try {
String query = "INSERT INTO reg.register
(" +
"regid, co_cd,
ext, comments, salutation," +
"fname, lname, addr1, addr2, addr3, " +
" city, state, zip, country, " +
"email, phone, checked_in, morning_session, afternoon_session,
fax, " +
"harborside_hotel, reception, attending_date, dinner_party,
" +
"training_session, refresher, title" +
") VALUES ('" +
s + " ', '" +
CompanyIn + " ', '" +
ExtensionIn + " ', '" +
CommentsIn + " ', '" +
SalutationIn + " ', '" +
FirstNameIn + " ', '" +
LastNameIn + " ', '" +
AddressIn + " ', '" +
Line2In + " ', '" +
Line3In + " ', '" +
CityIn + " ', '" +
StateIn + " ', '" +
ZipcodeIn + " ', '" +
CountryIn + " ', '" +
EmailIn + " ', '" +
PhoneIn + " ', '" +
" ', '" +
MorningIn + " ', '" +
AfternoonIn + " ', '" +
FaxIn + " ', '" +
HarborsideHotelIn + " ', '" +
ReceptionIn + " ', '" +
AttendingDateIn + " ', '" +
PartyIn + " ', '" +
TrainingSessionIn + " ', '" +
RefresherIn + " ', '" +
TitleIn + " ')";
Statement statement =
jdbcConnect.createStatement();
int result = statement.executeUpdate( query );
if ( result == 1 ){
buf.append( "<big><br>Thank
you for registering for CCA's Insight 204 Symposium,"
);
buf.append( "<br>being held in Boston, MA.,
June 5-8, 2005." );
buf.append( "<br><br>Your Registration
ID is <b>" + s + "</b> <br>
<br>" );
buf.append( "<br>If you have any questions
or need to make changes, please contact Cheryl Hanlin
\n" );
buf.append( "<br>at (508) 270-6666, ext 567.
<br> <br>" );
buf.append( "<br>We look forward to seeing
you in Boston in June! </big>" );
buf.append( "<br><br><a href='http://www.cca-int.com'>Click
here to go to CCA's main page</a>");
emailReply(buf);
}
else {
session.invalidate();
// erase session
buf.append( "<br>Registration
Failed! \n" );
buf.append( "<br>Please
try again later, or Call CCA Support \n" );
}
}
catch ( SQLException
sqlex ) {
session.invalidate();
// erase session
buf.append( "<br>Registration
Failed! \n" );
buf.append( "<br>Please
try again later, or Call CCA Support \n" );
}
}
}
|