• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

check user name avialability using jsp and mysql

 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

For my web application i have a text field for username i need to check username availability from mysql database and should display status below the text field as available or unavailable..

i have changed my code like this its partially working So please go through this code and help me....




This is my JSP:




And this is my servlet:





Only else clause is working and if clause is not working

Hello please some one help me on this....
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the given user name exists in table? If yes try to trim the variable it might be containing spaces.

 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Swastik Dey:

Tried as you said but the same problem persists... only else clause is working even though am giving some new username which is not there in the db its showing username not available and for username that is already available also its displaying the same....
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Print the uname variable in servlet, and see what you are getting in that variable.
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its printing null dono y??
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sunaina agarwal wrote:its printing null dono y??


Please use proper words (http://www.coderanch.com/how-to/java/UseRealWords)

Is the UserName stored in the database a different case (written in capitals or small letters)?
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Its properly spelled....
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us the complete jsp pge, let us see how the form data is submitted. We couldn't see any form tag in the page.
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is this line?



I would assume that you are not checking including the "@gmail.com" against the database?
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No "@gmail.com" is not included
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
onSubmit you seem to be calling a js function validate(), what does the function do? I hope this function is not doing some foul play. Instead of txtUserName can you retrieve value of another field.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try running the select query directly against the database and see what happens. It might perhaps give you a clue as to what is wrong with your code.
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question of sql query comes later. The basic problem here is when she retrieves the value request.getParameter, it is coming as null.
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the code of validate()?
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From jsp page if you remove the onSubmit=validate() call , (I mean just submit the form without any validation) does it make any difference?
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no difference....
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try any other field? Are you getting null for field or just txtUsername?
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have too many embedded java scripts inside page. Tough to know what they are doing. But what appears is just before form submission it's somehow becoming null/empty.
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my check_user.js code jus posted it for your reference. I hope somewhere in this code "txtUsername" is not becoming null??



 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got a clue i.e., after submitting the form the uname is getting the input value as some name but for checking username availability am getting the parameter before submitting the form its on Keyup function so its getting null value... But i don't know how to resolve it...
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just for a test, change the method to get from post. So in this case the values should appear in the querystring in the url. Just see what you are getting there against txtUsername.
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing is getting displayed in the url and as i have given print statement same null is getting printed.... K let me put it this way... Now in the servlet how to get each string parameter immediately on typing each letter in the jsp text field.... before submitting the form....
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean onkeyup it's submitting the request to servlet and when the response comes back it's becoming null?
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes exactly...
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want that? Is it not an overload on the servlet? On every keystroke submitting request. What is the requirement?
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to check username availability... I need it...
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. But imagine a scenario, 1000 users are using your web site to register. So for 1000 users you are checking the availability on each key stroke, so imagine the overhead and performance issue of the server. Correct me if I am wrong.
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so what do you expect me to do.... imagine there is a user name called Rahul already existing in the database and another user tries to type the same user name so till he types Rahu the status should show available only ryt only after he types "L" the status should display username already taken....??
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okey.. So your issue is, when the response comes back after validating on keyup the entire page is reloaded.
 
sunaina agarwal
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes
 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you probably need AJAX in this case, or the other option could be you have to persist the values (session/cookies) and when the page is reloaded display the persisted values. Although AJAX seems to be a better approach.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic