• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Servlet

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
did you compile your java code?
 
Ammy Singh
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ofcourse i did
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Aman", please check your private messages for an important administrative matter. Again.
 
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what exactly was the problem?
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic