Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Check username availability in JSP - Any ideas?  RSS feed

 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there!

I am developing a web application and have the following issue:
When registering new users I have a for within JSP page and call Java Servlet when submitting registration.
I use JavaScript functions for validating data entered. I also have a separate singleton Java class with LinkedHashMap in it for keeping user's data.
The thing I could not get to work is checking username availability. Since user's data is kept in LinkedHashMap where username is a key, I can't have two users with the same username. So what I wanted to do is to have a link on registration form, something like "Check availability", that would do the job.

I would appreciate if anyone could give me instructions on how to get this thing to work.

Thanks in advance and sorry for (maybe) not that great english!

Cheers!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a job for Ajax to me.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not familiar with Ajax, so it would be difficult to accomplish.
Any other idea?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66187
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you are not willing to learn anything new to accomplish this, what are you willing to do?

The only other viable alternatives are to perform a full-page refresh, or preload the user data into JavaScript data for checking. Neither of which is a particularly good solution.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point is not that I don't want to learn anything new, simply I thought it can be done otherwise.
Anyway, it's an exam-project, so I can use technologies that are specified in assignment, and Ajax is certainly not one.

Thanks, anyway!
 
Paul Clapham
Sheriff
Posts: 22480
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Ajax? Then your "Check Availability" button will just have to send a request to a servlet and/or JSP which does the check and returns a result page with the answer.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37230
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Bear's point is that if there are restrictions on the answers you can accept, it is helpful to state them upfront.

So now you have:
click a button
servlet that looks up usernames
redirect to JSP with status

What are you stuck on.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, the point is that I actually must submit the form, check availability within servlet and then redirect it to some page with error message saying that username is not available.
I was stuck 'cause I thought the job could be done before submitting, within jsp itself.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It could, if you use one of the other solutions suggested.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37230
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:I was stuck 'cause I thought the job could be done before submitting, within jsp itself.

You mean within the HTML page. A JSP is just used to render the HTML.

Once the JSP is rendered, there is only one way to interact without refreshing the page - JavaScript. It can be all client side JavaScript or AJAX which goes to the server. You said you didn't want to use AJAX. And client side JavaScript would need a list of all existing user ids to run which would be a horrible idea from a security perspective.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!