• Post Reply Bookmark Topic Watch Topic
  • New Topic

ask for login

 
albert sie
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to built up a simple login page. what i do is just let user to key in the username and password then will compare to the database . after compare if the username and password valid then direct to the specific. wat the code to use for direct the link automatically without clicking after validation....

thanks,
regards
albert
 
Eric C Lee
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm assuming you are using a html/jsp page to take the login information. When the user click on the submit button, you could then use the POST method to post to a JSP or Servlet.


After you post the login information to a jsp, you could get the username and password from the request:


In your jsp page you could then validate the information against the database. If the user enter correct password then you redirect to a secured page, otherwise, you can just redirect to a invalid HTML page, or redirect back to the login page.

It would be helpful if you can look up Model View Controller pattern(MVC) for doing this kind of thing to separate View(Login Page) from the business logic(Login Validation).

I didn't give you the complete code, but this is the general flow that you can follow.

Good luck!
[ February 23, 2007: Message edited by: Eric C Lee ]
 
Kai Witte
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

best practice is to use JAAS, in your case with login-method FORM. Look up the general way in the Servlet specification and the way to map it to the relational database in your web container manual.

Kai
 
Jan Cumps
Bartender
Posts: 2614
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest solution is to configure Basic Authentication.
A window will pop up and ask for username and password when a protected url (page) is requested.

It's not the most advanced and secure solution, but it will do the job in a lot of situations.

A simple guide can be found on ONJava.

See section 5. Configuring Basic Authentication.

Regards, Jan
 
albert sie
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i want is the method to redirect to specific page code after the validation has done

any expert here can tell me please. thank you

regards
albert
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by albert sie:
what i want is the method to redirect to specific page


Are you asking how to perform a redirect?

Check the API for HttpServletResponse.
 
albert sie
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya when i match the username and password with the database, if match i will go to certain page and if no i will go to another page. how to set it to redirect to that page?
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use <jsp:forward> the way you can forward you page.. to next OR another way to forward by using RequestDispatcher Interface..
[ February 25, 2007: Message edited by: Saif uddin ]
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya when i match the username and password with the database, if match i will go to certain page and if no i will go to another page. how to set it to redirect to that page?


This can be configured with form authentication. Success and error pages

<jsp:forward>


I would not recommend using the "forward" standard action when the JSP is actually supposed to be a view.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!