| | |
[ask]validation for user name registration
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2008
Posts: 2
Reputation:
Solved Threads: 0
hallo...this is my first post..
i want to validation my registration..
if there are anyone to regis but the username is already(in database), there are message " sorry, choose the different name please"
i have no idea, i have tried but always failed...
o..yeah i use ms.accsess for my database..and JSP ( not jsp 2 or something like that)
help me please...
i'm so poor in jsp & access ( newbie)
and please tell me where the false from my script..
sorry bad english...
i want to validation my registration..
if there are anyone to regis but the username is already(in database), there are message " sorry, choose the different name please"
i have no idea, i have tried but always failed...
o..yeah i use ms.accsess for my database..and JSP ( not jsp 2 or something like that)
help me please...
i'm so poor in jsp & access ( newbie)
and please tell me where the false from my script..
sorry bad english...
•
•
Join Date: Dec 2008
Posts: 2
Reputation:
Solved Threads: 0
JSP Syntax (Toggle Plain Text)
register.jsp <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-image: url(); } --> </style></head> <body> <table width="800" height="1028" border="0" align="center"> <tr> <td width="795" height="134"><img src="banner2.gif" width="795" height="95" align="top" /><br /> <img src="home.gif" width="132" height="35" /><img src="team.gif" width="132" height="35" /><img src="players.gif" width="132" height="35" /><img src="message.gif" width="132" height="35" /><img src="tranfer.gif" width="132" height="35" /><img src="about.gif" width="135" height="35" /></td> </tr> <tr> <td height="788" align="left" valign="top"><form id="form1" name="form1" method="post" action="doregister.jsp"> <p> </p> <table width="200" border="1"> <tr> <td colspan="2"><div align="center">Register</div></td> </tr> <tr> <td width="83">Username</td> <td width="101"><label> <input type="text" name="txtuser" id="txtuser" /> </label></td> </tr> <tr> <td>Password</td> <td><label> <input type="password" name="txtpass" id="txtpass" /> </label></td> </tr> <tr> <td>Age</td> <td><label> <input type="text" name="txtage" id="txtage" /> </label></td> </tr> <tr> <td>Club</td> <td><label> <select name="selectclub" id="selectclub"> <option>Manchaster United</option> <option>Inter Milan</option> </select> </label></td> </tr> <tr> <td colspan="2"><label> <div align="center"> <input type="submit" name="button" id="button" value="Submit" /> </div> </label></td> </tr> <tr> <td height="62" colspan="2"> <% String error = request.getParameter("err"); if(error!=null) out.println(error); %></td> </tr> </table> </form> <p> </p></td> </tr> <tr> <td height="80" align="left" valign="top"><p> </p> <p> </p></td> </tr> </table> </body> </html> doregister.jsp <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <%@ include file ="konek.jsp" %> <% String user = request.getParameter("txtuser"); String pass = request.getParameter("txtpass"); String age = request.getParameter("txtage"); String query = null; if(user == null || user.equals("")) { response.sendRedirect("register.jsp?err = please fill the username"); } else if (user != null) { query = "select username from msUser where username like '%"+user+"%'"; } else if(pass == null || pass.equals("")) { response.sendRedirect("register.jsp?err = please fill the pass"); } else if(age == null || age.equals("")) { response.sendRedirect("register.jsp?err = please fill the age"); } else { if(user == query) { response.sendRedirect("register.jsp?err = please choose a diffrent user name"); } else if(user != query) { st.executeUpdate("insert into msUser values('"+user+"','"+pass+"',"+age+")"); con.close(); response.sendRedirect("home.jsp"); } } %>
sorry, no need to download the attachement...here is the code..
First point I suggest is read the Read-Me thread which is the first thread in the JSP forum, You are performing database operations from directly withing your JSP page which is considered a bad practice, the above thread will guide you on how to go about organizing your code nicely so that when you get on real world projects in JSP you will be thorough with the right practice.
Now let us check how your coding is going on. First thing I see is you are failing to consider all the circumstances and you have just not traced mentally how your
for ex consider this :-
In the "if" condition you are already checking wheteher
Now just take a look at your query:-
This would list all the users to you which contain the current user's username.
For example if the current user wants to register the user name as "dracula" and if a user called "dracula1" already exists then the above select query would give you the details of user "dracula1" and hence your system would not allow the user "dracula" to be created even if no such user exists.
Your query should have been:-
Now we may have corrected the query, but you have not fired the query in the database to check if the user exists !!!
Also why are you checking if
First thing is that when you want to compare two strings you do not use the
Also if your consider this logically it is absolutely incorrect. What is the use of comparing the
According to me you still do not have any firm foundation of the language so I suggest you first get your basics of Java strong, by going through tutorials mentioned in this thread.
Next go through the JDBC tutorial, note in core Java only and once you have established yourself firmly in Java only then jump to JSP (else you will just find yourself coming back time and again to clear your core java concepts).
Also you need to read a little background information about JSPs cause you seem to be confused as to what is meant by JSP 2.0 standard etc. Any book on JSP worth its salt will cover these basic topics in the first or second chapter itself.
BTW its Manchester United and not Manchaster, if your are going to use the name of my favourite, you better spell it correctly !!!
Now let us check how your coding is going on. First thing I see is you are failing to consider all the circumstances and you have just not traced mentally how your
if and else if statements will be executed.for ex consider this :-
java Syntax (Toggle Plain Text)
if(user == null || user.equals("")) { response.sendRedirect("register.jsp?err = please fill the username"); } else if (user != null) { query = "select username from msUser where username like '%"+user+"%'"; }
In the "if" condition you are already checking wheteher
user == null or blank user.equals("") so why do you need to check again in the else if (user != null) , the code in that else if block could been easily put in the else block.Now just take a look at your query:-
sql Syntax (Toggle Plain Text)
SELECT username FROM msUser WHERE username LIKE '%"+user+"%'
This would list all the users to you which contain the current user's username.
For example if the current user wants to register the user name as "dracula" and if a user called "dracula1" already exists then the above select query would give you the details of user "dracula1" and hence your system would not allow the user "dracula" to be created even if no such user exists.
Your query should have been:-
sql Syntax (Toggle Plain Text)
SELECT password FROM msUser WHERE user='"+user+"';
Now we may have corrected the query, but you have not fired the query in the database to check if the user exists !!!
Also why are you checking if
user == query , there is everything wrong in that also.First thing is that when you want to compare two strings you do not use the
== operator, you use the equals() or equalsIgnoreCase() method of the String class.Also if your consider this logically it is absolutely incorrect. What is the use of comparing the
According to me you still do not have any firm foundation of the language so I suggest you first get your basics of Java strong, by going through tutorials mentioned in this thread.
Next go through the JDBC tutorial, note in core Java only and once you have established yourself firmly in Java only then jump to JSP (else you will just find yourself coming back time and again to clear your core java concepts).
Also you need to read a little background information about JSPs cause you seem to be confused as to what is meant by JSP 2.0 standard etc. Any book on JSP worth its salt will cover these basic topics in the first or second chapter itself.
BTW its Manchester United and not Manchaster, if your are going to use the name of my favourite, you better spell it correctly !!!
Last edited by stephen84s; Dec 3rd, 2008 at 2:46 am.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
![]() |
Similar Threads
- ASP.NET Registration Page (ASP.NET)
- XML Schema/Relational Schema in DB29 (XML, XSLT and XPATH)
- Validation (Geeks' Lounge)
- Registration and Login scripts using VB and Oledbconnection to Access Database (ASP.NET)
- Can Someone please check my project & comment/tips (C)
- Hot Offers Hijack and Others (Viruses, Spyware and other Nasties)
- Variable Validation & MYSQL (PHP)
Other Threads in the JSP Forum
- Previous Thread: jsp with ajax
- Next Thread: Jsp tag
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish imagetodatabse imageupload internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial video web






