This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes Writing a simple login app using JSP & MS Access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Writing a simple login app using JSP & MS Access" Watch "Writing a simple login app using JSP & MS Access" New topic
Author

Writing a simple login app using JSP & MS Access

Sukrit Sulochana
Greenhorn

Joined: Oct 13, 2005
Posts: 21
Hello,

I'm a newbie to the Servlets and JSP world. I was reading the excellent primer on Servlets and JSP titled "Head first Servlets and JSP." I have read a few chapters and wish to utilize my knowledge so far in writing a simple login program using JSP. The database that contains ID's and passwords will be in MS Access. I am using Tomcat as the container. My initial questions are:

1. How do I access the database from the JSP? Are there examples on the internet that show me how to do it? Do I have to use JDBC?

2. Do I have to have a separate front end HTML page that handles the login and then forwards the request to the JSP, or can the JSP itself be the front end?

3. Do I need to write an XML deploment descriptor for the JSP?

I have these questions for now and would appreciate any help that I can get. I will continue to post more questions in this thread as I progress.

Thanks in advance for helping me.
Sincerely,
Rajneesh
Bimal Patel
Ranch Hand

Joined: Aug 29, 2003
Posts: 130
Hi,



1. How do I access the database from the JSP? Are there examples on the internet that show me how to do it? Do I have to use JDBC?

Ans: You have to use JDBC. There is no other way for that!!! Just use the JDBC code to access the DB as you're doing the same by a java application.



2. Do I have to have a separate front end HTML page that handles the login and then forwards the request to the JSP, or can the JSP itself be the front end?

Ans: You can only have one JSP page which handles both the things. Or you can have two saperate JSPs, one for the main page and one for just processing the request and validating the same. And that page may responsible to take the request ahead for any other page like welcome <user>.



3. Do I need to write an XML deploment descriptor for the JSP?

Ans: No. You don't need to write. If you want to specify an init parameter for the JSP, yes you need to specify that in web.xml file.


Work Hard, Expect The Worst...<br /> <br />Bimal R. Patel<br />(SCJP 1.2, SCWCD 1.4)
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Rajneesh

I know you are learning, but then also you should surely think of using the MVC pattern. Design a login page and use the JSP for the login. But later make sure you shift this pattern to MVC.

The following may help you.

1. The login page can be a simple HTML or JSP. Better keep it a JSP as later in case you want some JSP functionality in it it would be better.
2. The JSP would forward the request i.e. the username and password to the server along with a code telling what to do. Lets call that code as the actionCode.
3. When the servlet recieves the request and sees the actionCode it would direct the request to the Java class and it would authenticate the request and send back the response to the servlet.
4. The servlet would then send back the response to the JSP indicating success or failure.
Sukrit Sulochana
Greenhorn

Joined: Oct 13, 2005
Posts: 21
Thank you, Anupam and Bimal. I have decided to use the MVC pattern, and I'm going to use Websphere Server instead of Tomcat because I want to learn that. Also instead of a simple login page I am going to develop an address book application.

My question:

In the book I read that the model is usually a simple Java class which talks to the database as needed. Therefore do I really need to learn how to use JDBC with JSP's, or can I just do it from the Java class?

I am basically following Anupam's design.

Thanks,
Rajneesh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60080
    
  65

The JDBC should be completely hidden from the UI in well-factored model classes. In my opinion, the terms JDBC and JSP should never both be used in the same sentence.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sukrit Sulochana
Greenhorn

Joined: Oct 13, 2005
Posts: 21
Websphere is temporarily unavialable to me; so I'm using Tomcat for the time being.

Does anyone know of any free JDBC driver for connecting Java with an MS Access database?

Thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Rajneesh Joshi:
Websphere is temporarily unavialable to me; so I'm using Tomcat for the time being.


Hopefully, if you're lucky, you'll get to stay with it.

If not, make sure to find out which version of the servlet and JSP specs the version of Websphere you plan on using supports. Tomcat is generally far ahead of the commercial containers in this respect. You don't want to find out when you switch that you have to re-write lots of your code to get it to comply with an older spec.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bimal Patel
Ranch Hand

Joined: Aug 29, 2003
Posts: 130
Hi Rajneesh,

Originally posted by Rajneesh Joshi:

Does anyone know of any free JDBC driver for connecting Java with an MS Access database?


Its nice that you're using MVC. For connecting to the database like MS Access, you need to use type 1 driver i.e. JDBC/ODBC bridge. You don't need to have any other API for that. Just simply gether some material on that kind of driver. Its really very easy.
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Though I have the code. But I would prefer you to search for it. This would also let you learn a few things still in case you are not able to get through I'll post it.

Secondly thanks that you are following my design. That's the MVC design pattern.

As Bear said you should not have any code in the JSP for DB access.

The flow should be like

JSP -> Servlet -> Java Class/another JSP

The return path should be the exact opposite of the above.

Your DB access code should be in the java classes only.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
As Bimal already pointed out, the JDBC-ODBC driver is already part of the JDK. You just need to set up the datasource (search the net or this forum), and write the code to do what you want.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Sukrit Sulochana
Greenhorn

Joined: Oct 13, 2005
Posts: 21
Thanks, guys. I have now installed Webshere and wish to continue on that. I understand that it has its own JDBC driver.

Is there any tutorial on the internet that shows me how to use Webshere?

Thanks,
Rajneesh
Sukrit Sulochana
Greenhorn

Joined: Oct 13, 2005
Posts: 21
Hi,

In my address book application should I have different controller servlets for each task i.e. adding new, updating existing records or deleting? or just one? Likewise should I have different model java classes for each of these functions?

Thanks for your help.

--Rajneesh
charles sam
Greenhorn

Joined: Aug 18, 2006
Posts: 1
Hi Rajneesh...
I saw your comment. I would like to put my step forward in JAVA. So get me some tips and Ebooks. Even I have tried to do a simple login page using Servlets, Jsp and JDBC .. I am confused. How to start.. Whether to start from an HTML page or JSP page. If anyone have login form(My login form contains name and password and accessing values from database) using JDBC, servlet and JSP made application let me know it..
My doubts are:
How do we link JSP or HTML page to JDBC through servlet?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by charles sam:
Hi Rajneesh...
I saw your comment. I would like to put my step forward in JAVA. So get me some tips and Ebooks. Even I have tried to do a simple login page using Servlets, Jsp and JDBC .. I am confused. How to start.. Whether to start from an HTML page or JSP page. If anyone have login form(My login form contains name and password and accessing values from database) using JDBC, servlet and JSP made application let me know it..
My doubts are:
How do we link JSP or HTML page to JDBC through servlet?


Charles,
Welcome to Javaranch.
This thread is 7 months old.
Most of the participants have probably moved on by now.
Your best bet is to start a new topic with your question.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing a simple login app using JSP & MS Access
 
Similar Threads
HELP WITH JSP?
conversion of month
JDBC type 3 driver
how to connect Jsp to servlet to process parameters
creating a Loginpage.jsp in JSP with LOGIN id and Password.