• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet

 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you compile your java code?
 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ofcourse i did
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Aman", please check your private messages for an important administrative matter. Again.
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what exactly was the problem?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic