Hi JSP techys,
I am stuck in getting a good boolean result using servlet. My program is doing some error checking with the form input information entered. If not all the information is entered,I am trying to print string "Please enter all the information", if all the values are entered in the form, I would like my program to print "Thanks You". I am calling the servlet using HTML form. I am in trouble using boolean settings. Any help will help me to proceed good. Below are the 2 files . ProcessInfo.java and info.html.
--------------------
ProcessInfo.java
--------------------
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ProcessInfo extends javax.servlet.http.HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setContentType("text/html"
String firstName, lastName;
String address, phone, fax, email;
boolean all_info;
PrintWriter pw = res.getWriter();
Enumeration paramNames = req.getParameterNames();
pw.println("<html>"
pw.println("<head><title>Processing Information Form</title><head>"
pw.println("<body>"
//all_info = false;
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
String[] paramValues = req.getParameterValues(paramName);
String paramValue = paramValues[0];
if (paramName == null || paramValue.length() == 0){
pw.println("<BR>*" + paramName + "\t<BR>\n"
all_info = false;
}
else {
pw.println("<BR>" + paramName + "\t" + paramValue +"<BR>\n"
//all_info = true;
}
}
if (all_info = false){
pw.println("Please enter all information" + "<BR>"
}
pw.println("</body>"
pw.println("</html>"
pw.close();
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
---------------------
Info.html
---------------------
<html>
<head>
<title>Lab01-JSP Programming:Info.html</title>
</head>
<!---- Info.html --->
<body>
<H4> Write an HTML page with a form that takes first name,last name,address,phone number, email address with a submit button</H4>
<form action="servlet/ProcessInfo" method="Post">
Enter:<BR>
<BR>
Fist Name:<BR><input type="text" valign="middle" Name="FirstName" value="" size="20"><BR>
Last Name:<BR><input type="text" valign="middle" Name="LastName" value="" size="20"><BR>
Address:<BR><input type="text" valign="middle" Name="Address" value="" size="20" maxlength=120><BR>
Phone:<BR><input type="text" valign="middle" Name="PhoneNumber" value=""><BR>
Fax:<BR><input type="text" valign="middle" Name="FaxNumber" value=""><BR>
Email:<BR><input type="text" valign="middle" Name="EmailAddress" value=""><BR>
<BR>
<input type="submit" value="Submit"><BR>
</form>
</body>
</html>
---------------------
I am stuck in getting a good boolean result using servlet. My program is doing some error checking with the form input information entered. If not all the information is entered,I am trying to print string "Please enter all the information", if all the values are entered in the form, I would like my program to print "Thanks You". I am calling the servlet using HTML form. I am in trouble using boolean settings. Any help will help me to proceed good. Below are the 2 files . ProcessInfo.java and info.html.
--------------------
ProcessInfo.java
--------------------
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ProcessInfo extends javax.servlet.http.HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setContentType("text/html"
String firstName, lastName;
String address, phone, fax, email;
boolean all_info;
PrintWriter pw = res.getWriter();
Enumeration paramNames = req.getParameterNames();
pw.println("<html>"
pw.println("<head><title>Processing Information Form</title><head>"
pw.println("<body>"
//all_info = false;
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
String[] paramValues = req.getParameterValues(paramName);
String paramValue = paramValues[0];
if (paramName == null || paramValue.length() == 0){
pw.println("<BR>*" + paramName + "\t<BR>\n"
all_info = false;
}
else {
pw.println("<BR>" + paramName + "\t" + paramValue +"<BR>\n"
//all_info = true;
}
}
if (all_info = false){
pw.println("Please enter all information" + "<BR>"
}
pw.println("</body>"
pw.println("</html>"
pw.close();
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
---------------------
Info.html
---------------------
<html>
<head>
<title>Lab01-JSP Programming:Info.html</title>
</head>
<!---- Info.html --->
<body>
<H4> Write an HTML page with a form that takes first name,last name,address,phone number, email address with a submit button</H4>
<form action="servlet/ProcessInfo" method="Post">
Enter:<BR>
<BR>
Fist Name:<BR><input type="text" valign="middle" Name="FirstName" value="" size="20"><BR>
Last Name:<BR><input type="text" valign="middle" Name="LastName" value="" size="20"><BR>
Address:<BR><input type="text" valign="middle" Name="Address" value="" size="20" maxlength=120><BR>
Phone:<BR><input type="text" valign="middle" Name="PhoneNumber" value=""><BR>
Fax:<BR><input type="text" valign="middle" Name="FaxNumber" value=""><BR>
Email:<BR><input type="text" valign="middle" Name="EmailAddress" value=""><BR>
<BR>
<input type="submit" value="Submit"><BR>
</form>
</body>
</html>
---------------------