• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

validation

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
some one please tell me where i did mistake given below...My request is not going to servlet....I provided html and servlet code below

1. <html><center>



2. <form name="f1"onsubmit="return validate()"action="./validate"method="get">

3. username: <input type="text"name="t1"id="t1">


4. password: <input type="password"name="p1"id="t2">


5. <input type="submit"value="sign in">

6. </form>

7. <script>

8. function validate()

9. {

10. if((f1.t1.value.length==0)||(f1.t2.value.length==0))

11. {

12. document.getElementById("demo").innerHTML='<h1>'+"invalid username and password"+''

13. }

14. return false;
}
</script>
</html>

servlet code:




import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class validate extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");

PrintWriter out = response.getWriter();

String uname=request.getParameter("t1");

String pwd=request.getParameter("p1");

out.println(uname+"\n"+pwd);
}
}
thanks...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you really not have spaces between the attributes of the <form> tag, or is that a copy/paste error? If you don't have them, start with that.

Also, what is the "mistake given below"? How are you using this page, and what happens when you use it?
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You also need <body> tags and a closing element for the <center> tag. Your <script> tag should have a "type" attribute.

Please use code tags instead of adding line numbers. Just click the "Code" button above and paste your code between the elements.
 
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In addition,
I cannot see any element with id or name
'demo' in your html page.
 
Sheriff
Posts: 67747
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 UseCodeTags when posting code. It will automatically assign line number so you don't have to.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sujesh Katri,

The "report" button is to report an issue / post / rancher to a moderator. It is not used to reply to posts. Please use the "post reply" button below to reply to posts.

Henry
 
sujesh Katri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if i type <script type="javascript">then my javascript validation code is not executed but it send requestparameters to servlet....in my actual code i tyep<p id=demo>but here it is missed.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


if i type <script type="javascript">then my javascript validation code is not executed but it send requestparameters to servlet....in my actual code i tyep<p id=demo>but here it is missed.


Sujesh,
Try as much as possible to include in double quotes the value of your attributes. Example: <p id="demo">
and it is recommended that you write <script type="text/javascript"> Please post your html page again. Get it right before thinking of the servlet.
 
sujesh Katri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<html><center><p id="demo"></p>
<form name="f1"onsubmit="return validate()"action="./validate"method="get">
username: <input type="text"name="t1"id="t1"><br>
password: <input type="password"name="p1"id="t2"><br>
<input type="submit"value="sign in">
</form>
<script type="text/javascript">
function validate()
{
if((f1.t1.value.length==0)||(f1.t2.value.length==0))
{
document.getElementById("demo").innerHTML='<font color=red><h1>'+"invalid username and password"+'</font>'
}
return false;
}
</script>
</center>
</html>

in the above html code if i write type="text/javascript" my validation i.e if did n't write username and password that error msg won't be display on my browser window......if i remove type attribure then my validation running properly but parameters not going to servlet...some one please provide me solution ...thanks.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Please UseCodeTags when posting code


So many people have told you so. Which editor do you use?
and the following if executed will return false no matter what so your servlet will not get called.

so try to move the return false; inside the if statement like this

 
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)which environment you are using ?

2)Did you map that URL of Servlet class in web.xml file .
 
sujesh Katri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using netbeans environment and i mapped url to web.xml....After moving return false into if block it is executed successfully....can i know the reason why it happens inside the if block only it is executing properly...Thank you very much.
 
sujesh Katri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the information clearly..Thanks
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
problem solved? or not?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic