Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This site is truly a marvel. Without a doubt the most comprehensive, friendly and just plain useful resource of its kind..."

Geography

Where in the world do Tek-Tips members come from?
preethib (Programmer)
11 Nov 01 22:36
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>
---------------------
wushutwist (Programmer)
11 Nov 01 22:46
First, make sure you initialize all_info to true when you declare it.  Second your compare statement is wrong, you are using = instead of ==.
preethib (Programmer)
14 Nov 01 18:27
Thanks!

follow up question:

If I want to send back the partially filled form, how would I approach it using JSP.

Preethi

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close