• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Writing a simple login app using JSP & MS Access

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sukrit Sulochana
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bimal Patel
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sukrit Sulochana
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic