• Post Reply Bookmark Topic Watch Topic
  • New Topic

Bean or Servlet or JSP?

 
Dinesh Kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Suppose I have a simple login page and the login is to be verified against a MySql database. There are 3 ways I can do this:
1. Have a jsp to accept the login and forward the login details (form post) to a servlet that connects to the database verifies the login and calls back the same jsp with "success" or "failure" flag in the query string. Have this flag examined in the original jsp and display login success or failure along with the original form for the user to post data again.
2. Have a jsp for accepting login data and another jsp to connect to the database and do exactly what the servlet does in (1) above.
3. Have a jsp accepting login data and it calls a bean for connecting to the database and verifying. One of the bean properties is set to indicate success or failure. The original jsp then queries the bean to display login success or failure. The bean can be in session scope to enable the login detail to persist and avoid another database connection if the same detail is needed later in the session.
The question is "What is the best way of doing this?"
Books discuss the possibility of all three ways but don't indicate what way to choose under what conditions.
Thanks in advance.
 
David Baranas
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you answered your own question. I would say the bean idea is the best and most elegant.
Can you take a look at my post right before yours. Any suggestions? Thanks!
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would simply use a servlet. Its made exactly for this type of thing, why bend other things to fit what a servlet does best.
1. is a good option.
2. is redundant.
3. jsp is only dynamic while the page is being generated. it can not respond to the user entering form data. This will require scripting.
With 1 you do not 'call back' the jsp as such. This is not an applet. You will process the data in the servlet, the forward the user back to the jsp page where you may display some additional data if you wish. typically one does not stay at the login page after successfully logging in. Besides all this, jsp already has a mechanism for authenticating a session with a form login page.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!