简体   繁体   English

检查用户名是否存在

[英]Check if user Name exist

What i want todo with Java and Javascript: 我想用Java和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 ? 但是是否可以将用户列表缓存在Application范围的变量中? If yes, how or where should i create a such variable ? 如果是,我应该如何或在哪里创建这样的变量? I use tomcat as server. 我使用tomcat作为服务器。 But no idea how i can do that. 但是不知道我该怎么做。

Or is it just fine, todo a check on the DB Server. 还是可以在DB Server上进行检查?

I want something similar like the Registration from hotmail 我想要类似的东西,例如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). 现在,您已经在页面中拥有了所有用户,并且可以检查输入的名称是否存在(必须在javascript中完成)。 The second method - after typing the name make an ajax call to the server and check in DB if exists. 第二种方法-输入名称后,对服务器进行ajax调用,并在DB中检查是否存在。 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. 首先,因为在每个http会话中,您都需要刷新整个缓存。 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. 其次,因为可能有多个http会话(多个用户试图创建一个帐户),并且您需要刷新整个缓存以验证新注册的登录名。 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! 第三,将整个用户名表临时存储在这样的变量中不是一个好习惯。假设您有10000000个登录名!

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! 只需使用ajax请求或servlet查询数据库,并确保您的登录名列具有索引!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在提交使用 Hibernate 创建用户之前检查用户名是否存在于数据库中? - How to check user name if exist in database before committing to create user with Hibernate? 放心检查名称是否存在于json响应中 - rest assured check the name is exist in the json response Gradle:检查文件是否存在而没有文件名 - Gradle: Check a file exist without file name Java:检查编译时是否存在给定的方法名称 - Java: Check if a given method name exist in compile time 无法检查文件系统中是否存在具有德语名称的文件 - Failed to check if file with German name is exist in the file system 如何检查现有用户并在会话中传入mongoCollection以进行设置? - how to check exist user and pass in mongoCollection for set in session? 检查 Cloud Firestore 中是否已存在用户 Google 登录凭据 - Check if user Google signin credentials already exist in Cloud Firestore JPA - 按名称检查用户是否存在于数据库中? - JPA - check if the user exists in the database by name? 通过用户输入的文件名在特定文件夹中搜索文件是否存在? - Search file by user input file name in a specific folder exist or not? 我希望让用户输入 .txt 文件名,如果文件名不存在,则重新提示用户。 这怎么可能? - I am wishing to ask the user to input a .txt file name, and re-prompt the user if the file name does not exist. How is this possible?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM