aspose file tools*
The moose likes Servlets and the fly likes Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet" Watch "Servlet" New topic
Author

Servlet

Ammy Singh
Ranch Hand

Joined: Oct 17, 2008
Posts: 36
I have a html signup.html page containing name, id ,password and confirm password paremeters, and in the servlet called SignUp.java i a condion that if either name or id are empty, then on clicking the submitt button it should print "One of the mandatary field is empty in the same page(in red color), but it is not doing that. please help me, thanks


here are the codes:


//signup.html

<html>
<body>
<h1 align = "center">New User Account</h1>
<form method = "GET" action = "SignUp">
<P>
Enter Your Name<span class="style1">*</span> :  
<Input Type = "text: name = "name"><br>
Enter User Name<span class="style1">*</span> :  
<Input Type = "text: name = "id"> @amanmail.com <br>
Enter Password<span class="style1">*</span> :    
<Input Type = "text: Password = "pwd"> <br>
Confirm Password<span class="style1">*</span>:  
<Input Type = "text: Password = "pwd1"> <br></P>
<P>
<input type = "SUBMIT" value = "Enter"> <br>
<a href = "Main.html">Return</a></P>

</form>

</body>
</html>

/////////////////////////////////////////

//SignUp.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SignUp extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException
{
res.setContentType("html/text");
PrintWriter pw = res.getWriter();

String name = req.getParameter("name");
String id = req.getParameter("id");
String pwd = req.getParameter("pwd");
String pwd1 = req.getParameter("pwd1");


if( (name == null) || (id == null) )
{

pw.println("One of the Mandatary field is empty");
}
else
{
pw.println("Congratulations" + name +" yow have successfully signup");
pw.println("Your login id is" +id);
}
}

public void doPost(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException
{

doGet(req,res);
}

}
///////////////////////////////////

//web.xml

<web-app>
<servlet>
<servlet-name> signup </servlet-name>
<servlet-class> SignUp </servlet-class>
</servlet>

<servlet-mapping>
<servlet-name> signup </servlet-name>
<url-pattern> /SignUp </url-pattern>
</servlet-mapping>
</web-app>


SCJP1.4
i luv Ranch it always helps...!!!
Hendy Setyo Mulyo
Ranch Hand

Joined: Dec 01, 2004
Posts: 219

Originally posted by Aman Chalotra:

if( (name == null) || (id == null) )
{

pw.println("One of the Mandatary field is empty");
}
else
{
pw.println("Congratulations" + name +" yow have successfully signup");
pw.println("Your login id is" +id);
}


You could change to

if( ("".equals(name) == true) || ("".equals(id) == true) )
{

pw.println("One of the Mandatary field is empty");
}
else
{
pw.println("Congratulations" + name +" yow have successfully signup");
pw.println("Your login id is" +id);
}


Hendy Setyo Mulyo
SCJP 1.4 (95%), SCWCD 1.4 (94%)
Ammy Singh
Ranch Hand

Joined: Oct 17, 2008
Posts: 36
Hi, thanks for your reply sir,
I tried your logic code, What it still has a problem as:
I tested it by empty values and it printed the else option i.e One of the Mandatary field is empty, but when i again supplied the values for each of the field, it still prints the same output: One of the Mandatary field is empty, i think it is not refressing the output page.
What is wrong here please help, thanks..
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

did you compile your java code?
Ammy Singh
Ranch Hand

Joined: Oct 17, 2008
Posts: 36
Ofcourse i did
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "Servlet" in a forum completely dedicated to questions on Servlets isn't very helpful.

Please go back and change your post to add a more meaningful subject by clicking the .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ammy Singh
Ranch Hand

Joined: Oct 17, 2008
Posts: 36
Before any rancher try to dig into the problem and help, i want to inform that the problem is solved, i was guilty for not looking into associated threads, thanks JavaRanch!!!1
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

"Aman", please check your private messages for an important administrative matter. Again.
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

what exactly was the problem?
 
Don't get me started about those stupid light bulbs.
 
subject: Servlet