Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using boolean, returns incorrect boolean value

Status
Not open for further replies.

preethib

Programmer
Jul 20, 2000
39
IN
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(&quot;<html>&quot;);
pw.println(&quot;<head><title>Processing Information Form</title><head>&quot;);
pw.println(&quot;<body>&quot;);

//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(&quot;<BR>*&quot; + paramName + &quot;\t<BR>\n&quot;);
all_info = false;
}
else {
pw.println(&quot;<BR>&quot; + paramName + &quot;\t&quot; + paramValue +&quot;<BR>\n&quot;);
//all_info = true;
}

}

if (all_info = false){
pw.println(&quot;Please enter all information&quot; + &quot;<BR>&quot;);
}

pw.println(&quot;</body>&quot;);
pw.println(&quot;</html>&quot;);
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=&quot;servlet/ProcessInfo&quot; method=&quot;Post&quot;>
Enter:<BR>
<BR>
Fist Name:<BR><input type=&quot;text&quot; valign=&quot;middle&quot; Name=&quot;FirstName&quot; value=&quot;&quot; size=&quot;20&quot;><BR>
Last Name:<BR><input type=&quot;text&quot; valign=&quot;middle&quot; Name=&quot;LastName&quot; value=&quot;&quot; size=&quot;20&quot;><BR>
Address:<BR><input type=&quot;text&quot; valign=&quot;middle&quot; Name=&quot;Address&quot; value=&quot;&quot; size=&quot;20&quot; maxlength=120><BR>
Phone:<BR><input type=&quot;text&quot; valign=&quot;middle&quot; Name=&quot;PhoneNumber&quot; value=&quot;&quot;><BR>
Fax:<BR><input type=&quot;text&quot; valign=&quot;middle&quot; Name=&quot;FaxNumber&quot; value=&quot;&quot;><BR>
Email:<BR><input type=&quot;text&quot; valign=&quot;middle&quot; Name=&quot;EmailAddress&quot; value=&quot;&quot;><BR>
<BR>
<input type=&quot;submit&quot; value=&quot;Submit&quot;><BR>
</form>

</body>
</html>
---------------------
 
First, make sure you initialize all_info to true when you declare it. Second your compare statement is wrong, you are using = instead of ==.
 
Thanks!

follow up question:

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

Preethi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top