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

checking username and password with database using JSP and jQuery.  RSS feed

 
kumar sapan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I created a login page in HTML and I created a servlet and when I submit the form it will go to the search servlet and display the user details if the username and password are correct or it will go to new page and display the error page.

But, now I want to display the error message on the login form itself if the username or password incorrect. How can I connect these two pages and display the error message if the login details are incorrect or it should display the user details if the login details are correct.
I want to display an error message instead of redirecting to the new page when the username or password incorrect. For that I am using jQuery.

Thank You.
Here is my code.

Login.html



SearchServlet
URL : search



 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first thing that you are doing wrong is putting Java code in a JSP. That code should be in a servlet. JSPs are for views only. Using them to process the submission is an egregious abuse of the technology.

Move the code to a servlet as your first step.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see you went ahead and edited your post after I answered. Please don't do that. Make new posts with updated code. Replacing the original post after I replied made my replies look like nonsense.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When your code has been refactored, please post it as a new reply and let us know what problems you are having with it.
 
kumar sapan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:When your code has been refactored, please post it as a new reply and let us know what problems you are having with it.




I created HTML page and servlet for login page and to display the user details. In that servlet, a new error page will be displayed if the username or password are wrong.
Now, I am trying to display the error message on the same login page if the user details are wrong by adding jQuery to it. In servlet I am doing the comparison with database
but I don't have any idea how to connect the jQuery to the servlet.

here is my code...




 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kumar sapan wrote:but I don't have any idea how to connect the jQuery to the servlet.

The Ajax URL should be the mapping for the servlet. Be sure to start the URL with the context path.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!