Here are the two error messages I'm receiving
ProcessForm.java:13: cannot resolve symbol
symbol : variable request
location: ProcessForm
String name = request.getParameter("LNAME");
the ^ is under the r in request.
Here is my code
//Import Servlet packages
import javax.servlet.*;
import javax.servlet.http.*;
//import other Java packages
import java.io.*;
import java.util.*;
public class ProcessForm extends HttpServlet{
protected void doPost(HttpServletResponse response) throws ServletException,
IOException{
//Get parameters from the request.
String name = request.getParameter("LNAME");
String id = request.getParameter("IDNUM");
//Compute fields
String message = null;
GregorianCalendar calendar = new GregorianCalendar();
if (calendar.get(Calendar.AM_PM) == Calendar.AM){
message = "Good Morning";
}
else {
message = "Good Afternoon";
}
//Set MIME type for the response
response.setContentType("text/html");
//Obtain a print writer object
PrintWriter out = response.getWriter();
//Write the content
out.println("<HTML>");
out.println("<BODY>");
out.println("<P>" + message + ", " + name + "</P>");
out.println("<P> Thank you for completing the form (" + id +
") with us.</P>");
out.println("</BODY>");
out.println("</HTML>");
out.close();
}
}
Which will be called by
<script Language="JavaScript">
<%@page import="java.util.Date"%>
<html>
<head>
function isEmailAddr(email)
{
var result = false;
var theStr = new String(email);
var index = theStr.indexOf("@");
if (index > 0)
{
var pindex = theStr.indexOf(".",index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}
return result;
}
function validRequired(formField,fieldLabel)
{
var result = true;
if (formField.value == "")
{
alert('Please enter a value for the "' + fieldLabel +'" field. Verify that all required fields are valid.');
formField.focus();
result = false;
}
return result;
}
function allDigits(str)
{
return inValidCharSet(str,"0123456789");
}
function inValidCharSet(str,charset)
{
var result = true;
// Note: doesn't use regular expressions to avoid early Mac browser bugs
for (var i=0;i<str.length;i++)
if (charset.indexOf(str.substr(i,1))<0)
{
result = false;
break;
}
return result;
}
function validEmail(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
{
alert("Please enter a complete email address in the form: loginID@messiah.edu");
formField.focus();
result = false;
}
return result;
}
function validNum(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
if (!allDigits(formField.value))
{
alert('Please enter a number for the "' + fieldLabel +'" field.');
formField.focus();
result = false;
}
}
return result;
}
function validInt(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
var num = parseInt(formField.value,10);
if (isNaN(num))
{
alert('Please enter a number for the "' + fieldLabel +'" field.');
formField.focus();
result = false;
}
}
return result;
}
function validDate(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
var elems = formField.value.split("/");
result = (elems.length == 3); // should be three components
if (result)
{
var month = parseInt(elems[0],10);
var day = parseInt(elems[1],10);
var year = parseInt(elems[2],10);
result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
allDigits(elems[1]) && (day > 0) && (day < 32) &&
allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
}
if (!result)
{
alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
formField.focus();
}
}
return result;
}
function validateForm(theForm)
{
// Customize these calls for your form
// Start ------->
if (!validRequired(theForm.IDNumber,"ID Number"))
return false;
if (!validRequired(theForm.last_name,"Last Name"))
return false;
if (!validRequired(theForm.first_name,"First Name"))
return false;
if (!validInt(theForm.PO_box,"Campus Box Number"))
return false;
if (!validEmail(theForm.email,"E-mail",true))
return false;
// <--------- End
return true;
}
</script>
<title>Internship Application</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#C0A02A" VLINK="#C0A02A" ALINK="#C0A02A" BACKGROUND="images/background.gif" NOSAVE>
Ther current time is <%= new Date().toString()%>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=3 WIDTH="620" >
<TR>
<TD ALIGN=LEFT VALIGN=TOP WIDTH="215">
<!-----------------Begin Form-------------------------------------------->
<P><B><FONT FACE="Arial,Helvetica" Font COLOR="#333333">Messiah College<br>Intership Program
- Application
</FONT></B><br>
<FONT COLOR="#000000">
<hr/>
Personal Information
<form method="post" action="mailto:dminich@messiah.edu">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=3 WIDTH="500" >
<TR bgcolor="#EEEEEF">
<TD width="50"><font face="Arial, Helvetica, sans-serif" size="2">
Last Name:</font></TD>
<TD colspan="2"><font color="#000000">
<input type="text" name="LName" size="25">
</font></TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
First Name:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="FName" SIZE="25">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
M.I.:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="MI" SIZE="5">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
ID #:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="IDNum" SIZE="6">
</TD>
</TR>
<TR bgcolor="#FFFFFF">
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Permanent Address:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="PAddress" SIZE="25">
</TD>
<TD width="150"><font face="Arial, Helvetica, sans-serif" size="2">
Social Security #:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="SSNum" SIZE="11">
</TD>
</TR>
<TR bgcolor="#EEEEEF">
<TD width="100"><font face="Arial, Helvetica, sans-serif" size="2">
City:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="City" SIZE="25">
</TD>
<TD width="50"><font face="Arial, Helvetica, sans-serif" size="2">
State:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="State" SIZE="2">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Zip:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="Zip" SIZE="5">
</TD>
<TD width="15"><font face="Arial, Helvetica, sans-serif" size="2">
Home Phone:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="AreaCode" SIZE="3">
</TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="Phone" SIZE="9">
</TD>
</TR>
<TR bgcolor="#FFFFFF">
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Capus Residence:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="CmpRes" SIZE="10">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Campus Phone:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="CmpPhone" SIZE="4">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Campus Box #:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="CmpBox" SIZE="4">
</TD>
</TR>
<TR bgcolor="#EEEEEF">
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Citizenship Status:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="Citizenship" SIZE="4">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Visa Type:</font></TD>
<TD colspan="5">
<INPUT TYPE="text" NAME="Citizenship" SIZE="20">
(if applicable)</TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="submit" name="Submit" value="Submit Application">
<INPUT TYPE="reset" VALUE="Clear Form">
</FORM>
</FONT>
<br>
<font face="Arial, Helvetica, sans-serif" size="2">If you have problems
or questions, e-mail <a href="mailto:dminich@messiah.edu">WebMaster</a></font>.
</TR>
</TABLE>
</body>
</html>
I'm just trying to compile the ProcessForm.java when the error appears. Here is my CLASSPATH as well.
C:\j2sdk1.4.0\jre\lib\rt.jar;C:\j2sdk1.4.0\lib\tools.jar;C:\Java\Tomcat\common\lib\servlet.jar;
Does anyone have any suggestions?
ProcessForm.java will not match the fields in the above .jsp file because I have just begun the process and wanted to make sure everything ran before I added all the fields and fine tuned things.
ProcessForm.java:13: cannot resolve symbol
symbol : variable request
location: ProcessForm
String name = request.getParameter("LNAME");
the ^ is under the r in request.
Here is my code
//Import Servlet packages
import javax.servlet.*;
import javax.servlet.http.*;
//import other Java packages
import java.io.*;
import java.util.*;
public class ProcessForm extends HttpServlet{
protected void doPost(HttpServletResponse response) throws ServletException,
IOException{
//Get parameters from the request.
String name = request.getParameter("LNAME");
String id = request.getParameter("IDNUM");
//Compute fields
String message = null;
GregorianCalendar calendar = new GregorianCalendar();
if (calendar.get(Calendar.AM_PM) == Calendar.AM){
message = "Good Morning";
}
else {
message = "Good Afternoon";
}
//Set MIME type for the response
response.setContentType("text/html");
//Obtain a print writer object
PrintWriter out = response.getWriter();
//Write the content
out.println("<HTML>");
out.println("<BODY>");
out.println("<P>" + message + ", " + name + "</P>");
out.println("<P> Thank you for completing the form (" + id +
") with us.</P>");
out.println("</BODY>");
out.println("</HTML>");
out.close();
}
}
Which will be called by
<script Language="JavaScript">
<%@page import="java.util.Date"%>
<html>
<head>
function isEmailAddr(email)
{
var result = false;
var theStr = new String(email);
var index = theStr.indexOf("@");
if (index > 0)
{
var pindex = theStr.indexOf(".",index);
if ((pindex > index+1) && (theStr.length > pindex+1))
result = true;
}
return result;
}
function validRequired(formField,fieldLabel)
{
var result = true;
if (formField.value == "")
{
alert('Please enter a value for the "' + fieldLabel +'" field. Verify that all required fields are valid.');
formField.focus();
result = false;
}
return result;
}
function allDigits(str)
{
return inValidCharSet(str,"0123456789");
}
function inValidCharSet(str,charset)
{
var result = true;
// Note: doesn't use regular expressions to avoid early Mac browser bugs
for (var i=0;i<str.length;i++)
if (charset.indexOf(str.substr(i,1))<0)
{
result = false;
break;
}
return result;
}
function validEmail(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
{
alert("Please enter a complete email address in the form: loginID@messiah.edu");
formField.focus();
result = false;
}
return result;
}
function validNum(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
if (!allDigits(formField.value))
{
alert('Please enter a number for the "' + fieldLabel +'" field.');
formField.focus();
result = false;
}
}
return result;
}
function validInt(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
var num = parseInt(formField.value,10);
if (isNaN(num))
{
alert('Please enter a number for the "' + fieldLabel +'" field.');
formField.focus();
result = false;
}
}
return result;
}
function validDate(formField,fieldLabel,required)
{
var result = true;
if (required && !validRequired(formField,fieldLabel))
result = false;
if (result)
{
var elems = formField.value.split("/");
result = (elems.length == 3); // should be three components
if (result)
{
var month = parseInt(elems[0],10);
var day = parseInt(elems[1],10);
var year = parseInt(elems[2],10);
result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
allDigits(elems[1]) && (day > 0) && (day < 32) &&
allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
}
if (!result)
{
alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
formField.focus();
}
}
return result;
}
function validateForm(theForm)
{
// Customize these calls for your form
// Start ------->
if (!validRequired(theForm.IDNumber,"ID Number"))
return false;
if (!validRequired(theForm.last_name,"Last Name"))
return false;
if (!validRequired(theForm.first_name,"First Name"))
return false;
if (!validInt(theForm.PO_box,"Campus Box Number"))
return false;
if (!validEmail(theForm.email,"E-mail",true))
return false;
// <--------- End
return true;
}
</script>
<title>Internship Application</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#C0A02A" VLINK="#C0A02A" ALINK="#C0A02A" BACKGROUND="images/background.gif" NOSAVE>
Ther current time is <%= new Date().toString()%>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=3 WIDTH="620" >
<TR>
<TD ALIGN=LEFT VALIGN=TOP WIDTH="215">
<!-----------------Begin Form-------------------------------------------->
<P><B><FONT FACE="Arial,Helvetica" Font COLOR="#333333">Messiah College<br>Intership Program
- Application
</FONT></B><br>
<FONT COLOR="#000000">
<hr/>
Personal Information
<form method="post" action="mailto:dminich@messiah.edu">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=3 WIDTH="500" >
<TR bgcolor="#EEEEEF">
<TD width="50"><font face="Arial, Helvetica, sans-serif" size="2">
Last Name:</font></TD>
<TD colspan="2"><font color="#000000">
<input type="text" name="LName" size="25">
</font></TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
First Name:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="FName" SIZE="25">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
M.I.:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="MI" SIZE="5">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
ID #:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="IDNum" SIZE="6">
</TD>
</TR>
<TR bgcolor="#FFFFFF">
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Permanent Address:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="PAddress" SIZE="25">
</TD>
<TD width="150"><font face="Arial, Helvetica, sans-serif" size="2">
Social Security #:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="SSNum" SIZE="11">
</TD>
</TR>
<TR bgcolor="#EEEEEF">
<TD width="100"><font face="Arial, Helvetica, sans-serif" size="2">
City:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="City" SIZE="25">
</TD>
<TD width="50"><font face="Arial, Helvetica, sans-serif" size="2">
State:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="State" SIZE="2">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Zip:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="Zip" SIZE="5">
</TD>
<TD width="15"><font face="Arial, Helvetica, sans-serif" size="2">
Home Phone:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="AreaCode" SIZE="3">
</TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="Phone" SIZE="9">
</TD>
</TR>
<TR bgcolor="#FFFFFF">
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Capus Residence:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="CmpRes" SIZE="10">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Campus Phone:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="CmpPhone" SIZE="4">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Campus Box #:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="CmpBox" SIZE="4">
</TD>
</TR>
<TR bgcolor="#EEEEEF">
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Citizenship Status:</font></TD>
<TD colspan="2">
<INPUT TYPE="text" NAME="Citizenship" SIZE="4">
</TD>
<TD width="139"><font face="Arial, Helvetica, sans-serif" size="2">
Visa Type:</font></TD>
<TD colspan="5">
<INPUT TYPE="text" NAME="Citizenship" SIZE="20">
(if applicable)</TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="submit" name="Submit" value="Submit Application">
<INPUT TYPE="reset" VALUE="Clear Form">
</FORM>
</FONT>
<br>
<font face="Arial, Helvetica, sans-serif" size="2">If you have problems
or questions, e-mail <a href="mailto:dminich@messiah.edu">WebMaster</a></font>.
</TR>
</TABLE>
</body>
</html>
I'm just trying to compile the ProcessForm.java when the error appears. Here is my CLASSPATH as well.
C:\j2sdk1.4.0\jre\lib\rt.jar;C:\j2sdk1.4.0\lib\tools.jar;C:\Java\Tomcat\common\lib\servlet.jar;
Does anyone have any suggestions?
ProcessForm.java will not match the fields in the above .jsp file because I have just begun the process and wanted to make sure everything ran before I added all the fields and fine tuned things.