Hi,
Below is the HTML form, with few form fields. on 'submit' of HTML form, I call the servlet. Basically what I want the servlet to do is if all the fields are filled return 'Thank You' information. Else the servlet should show an incomplete form as
"**** FieldName = <text box>"
And, on resubmit, the form should be reprocessed by the servlet and acknowledged(Thank You).
I am sure it's a trivial question. But the thing is I am beginner with JSP.
++++++++++++++++++++++++
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;
//String fn, ln, addr, fax, email, phno;
//String address, phone, fax, email;
String fn = req.getParameter("FirstName"
String ln = req.getParameter("LastName"
String addr = req.getParameter("Address"
String phno = req.getParameter("PhoneNumber"
String fax = req.getParameter("FaxNumber"
String email = req.getParameter("EmailAddress"
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 = true;
pw.println("<form action=\"servlet/ProcessInfo\" method=\"Get\">\n"
if ( ((fn.equals("" || fn == null))|| ((ln.equals("" || ln == null)) || ((addr.equals("" || addr == null)) || ((phno.equals("" || phno == null)) || ((fax.equals("" || fax == null)) || ((email.equals("" || email == null)) ) {
all_info = false;
}
else {
pw.println("<BR> FirstName" + "\t" + fn +"<BR>\n"
pw.println("<BR> LastName" + "\t" + ln +"<BR>\n"
pw.println("<BR> Address" + "\t" + addr +"<BR>\n"
pw.println("<BR> PhoneNumber" + "\t" + phno +"<BR>\n"
pw.println("<BR> Fax" + "\t" + fax +"<BR>\n"
pw.println("<BR> EmailAddress" + "\t" + email +"<BR>\n"
}
pw.println("</form>"
//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" + paramValue +"<BR>\n"
// }
//else if (paramName == null || paramValue.length() == 0){
// all_info = false;
// pw.println("<BR>*" + paramName + "\t<input type=\"text\""+ "Name=" + paramName + "value=\"\" size=\"20\">" +"<BR>\n"
// }
//else {
// pw.println("<BR>" + paramName + "\t" + paramValue +"<BR>\n"
// }
// }
pw.println("<BR>"
//pw.println("<BR>"
if (all_info == false){
pw.println("<form action=\" method=\"Post\">\n"
pw.println("Please enter all information" + "<BR>"
pw.println("<BR>"
pw.println("<input type=\"submit\" value=\"Submit\"><BR>"
pw.println("</form>"
}
else if (all_info == true){
pw.println("Thank You" + "<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" Name="FirstName" value="" size="20"><BR>
Last Name:<BR><input type="text" Name="LastName" value="" size="20"><BR>
Address:<BR><input type="text" Name="Address" value="" size="20" maxlength=120><BR>
Phone:<BR><input type="text" Name="PhoneNumber" value=""><BR>
Fax:<BR><input type="text" Name="FaxNumber" value=""><BR>
Email:<BR><input type="text" Name="EmailAddress" value=""><BR>
<BR>
<input type="submit" value="Submit"><BR>
</form>
</body>
</html>
Below is the HTML form, with few form fields. on 'submit' of HTML form, I call the servlet. Basically what I want the servlet to do is if all the fields are filled return 'Thank You' information. Else the servlet should show an incomplete form as
"**** FieldName = <text box>"
And, on resubmit, the form should be reprocessed by the servlet and acknowledged(Thank You).
I am sure it's a trivial question. But the thing is I am beginner with JSP.
++++++++++++++++++++++++
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;
//String fn, ln, addr, fax, email, phno;
//String address, phone, fax, email;
String fn = req.getParameter("FirstName"
String ln = req.getParameter("LastName"
String addr = req.getParameter("Address"
String phno = req.getParameter("PhoneNumber"
String fax = req.getParameter("FaxNumber"
String email = req.getParameter("EmailAddress"
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 = true;
pw.println("<form action=\"servlet/ProcessInfo\" method=\"Get\">\n"
if ( ((fn.equals("" || fn == null))|| ((ln.equals("" || ln == null)) || ((addr.equals("" || addr == null)) || ((phno.equals("" || phno == null)) || ((fax.equals("" || fax == null)) || ((email.equals("" || email == null)) ) {
all_info = false;
}
else {
pw.println("<BR> FirstName" + "\t" + fn +"<BR>\n"
pw.println("<BR> LastName" + "\t" + ln +"<BR>\n"
pw.println("<BR> Address" + "\t" + addr +"<BR>\n"
pw.println("<BR> PhoneNumber" + "\t" + phno +"<BR>\n"
pw.println("<BR> Fax" + "\t" + fax +"<BR>\n"
pw.println("<BR> EmailAddress" + "\t" + email +"<BR>\n"
}
pw.println("</form>"
//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" + paramValue +"<BR>\n"
// }
//else if (paramName == null || paramValue.length() == 0){
// all_info = false;
// pw.println("<BR>*" + paramName + "\t<input type=\"text\""+ "Name=" + paramName + "value=\"\" size=\"20\">" +"<BR>\n"
// }
//else {
// pw.println("<BR>" + paramName + "\t" + paramValue +"<BR>\n"
// }
// }
pw.println("<BR>"
//pw.println("<BR>"
if (all_info == false){
pw.println("<form action=\" method=\"Post\">\n"
pw.println("Please enter all information" + "<BR>"
pw.println("<BR>"
pw.println("<input type=\"submit\" value=\"Submit\"><BR>"
pw.println("</form>"
}
else if (all_info == true){
pw.println("Thank You" + "<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" Name="FirstName" value="" size="20"><BR>
Last Name:<BR><input type="text" Name="LastName" value="" size="20"><BR>
Address:<BR><input type="text" Name="Address" value="" size="20" maxlength=120><BR>
Phone:<BR><input type="text" Name="PhoneNumber" value=""><BR>
Fax:<BR><input type="text" Name="FaxNumber" value=""><BR>
Email:<BR><input type="text" Name="EmailAddress" value=""><BR>
<BR>
<input type="submit" value="Submit"><BR>
</form>
</body>
</html>