简体   繁体   中英

Check if user Name exist

What i want todo with Java and Javascript:

If a user try to register an Account, after he write the Login name and klick in the next field, there should be an immediately check, if the Login Name already exist.

My Question is now, what is the best performance way. I know, how i can check the username in the database, that is no Problem.

But is it possible to cache the List of users in a Application wide variable ? If yes, how or where should i create a such variable ? I use tomcat as server. But no idea how i can do that.

Or is it just fine, todo a check on the DB Server.

I want something similar like the Registration from hotmail

Thanks

Two ways to do it (and not thinking very hard). First - before loading the page, on the server side retrieve all user names, put the in a list and put the list in the request. Now you have all your user in the page and can check if the entered name exists (must do it in javascript). The second method - after typing the name make an ajax call to the server and check in DB if exists. Hope this helps.

It's not a good idea to cache all login names. First because at every http session, you need to refresh the whole cache. Second because it's possible to have multiple http sessions (multiple user trying to create an account) and you need to refresh the whole cache to verify new registrations login names. Third it's not a good practice to store temporary the whole user names table in such a variables.. imagine you have 10000000 login names!

With a cache, if two users want to register at the same time, and enters the same user login, both user login pass the validation !

Just query your database with an ajax request or a servlet and make sure your login name column has an index!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM