Apparatus:
- XAMPP Server/Apache Tomcat (Servlet Container)
- MS Access
- Web Browser
- Editor (Notepad ++)
- Java Development Kit
Things Covered in this post:
- Writing a java servlet program
- Creating user DSN and using it to connect Java web application to Database (.mdb)
- Deploying the servlet in Servlet Container
- Running the Application in Web Browser
Summary:
Step 1: Writing a basic HTML to construct User
Interface (home.html)
Step 2: Creating a Database in MS Access (Database2.mdb)
Step 3: Creating a DSN
Step 4: Writing a Java Servlet Program
Step 5: Compiling the Java Servlet Program
Step 6: Making the entry of the Java Servlet class in
the descriptor file (web.xml)
Step 7: Deploying the files in appropriate
directories
Step 8: Starting the Apache Tomcat module
Step 9: Checking the services running
Step 10: Running the Web Application on the Web
Browser
Steps in Detail:
Step 1: Writing a basic HTML to construct User Interface (home.html):
Step 2:
Creating a Database in MS Access (Database2.mdb):
The schema of table ‘result’ in Database2.mdb:
Field Name
|
Data Type
|
Field Size
|
RollNo (Primary Key)
|
Number
|
Long Integer
|
SName
|
Text
|
255
|
Branch
|
Text
|
255
|
CPI
|
Number
|
Double
|
Step 3: Creating a DSN:
Open System & Security/ Administrative Tools from
Control Panel. Select ODBC Data Sources (32-bit). Click on User DSN tab
and click Add…Button.
Select Driver do Microsoft Access (*.mdb).
Give the Data Source Name and click the Select… button to link the database file. Then click
the OK button.
Step 4: Writing a Java Servlet Program:
Step 5: Compiling
the Java Servlet Program:
First time compilation of Java Servlet Program would fail
because libraries (servlet-api.jar at location C:\xampp\tomcat\lib ) consisting
of servlet classes are not present in installed jdk. So you need to set the User
variable CLASSPATH in Environment Variables which you will find in Advanced
system settings in Control Panel as shown:
User variables:
Variable
|
Value
|
CLASSPATH
|
.;C:\xampp\tomcat\lib\servlet-api.jar
|
System variables:
Variable
|
Value
|
JAVA_HOME
|
C:\Program Files (x86)\Java\jdk1.6.0_24
|
Path
|
C:\Program Files (x86)\Java\jdk1.6.0_24\bin
|
Restart the computer after setting the variables.
Note: Locations may differ as per the different
installation directories.
Step 6:
Making the entry of the java servlet class in the descriptor file (web.xml):
web.xml
is a descriptor file which consists the information of all the servlet classes
present in the web application. The URLs to access the servlets are specified
in this file.
Step 7: Deploying the files in appropriate directories:
This zip file consists of
following files at following locations:
1.
home.html (C:\xampp\tomcat\webapps\student)
2.
Database2.mdb (C:\xampp\tomcat\webapps\student)
3.
web.xml (C:\xampp\tomcat\webapps\student\WEB-INF)
4.
Result.java (C:\xampp\tomcat\webapps\student\WEB-INF\classes)
5.
Result.class (C:\xampp\tomcat\webapps\student\WEB-INF\classes)
Step 8:
Starting the Apache Tomcat module:
Start the Apache Tomcat from XAMPP Control Panel.
Step 9:
Checking the services running:
In order to check whether the Apache Tomcat has started or
not, simply type the following URL in your web browser:
localhost:8080
Step
10: Running the Web Application on the Web Browser:
To run this web application, type the following URL:
http://localhost:8080/student/home.html
Note: Every time you make changes to your servlet
program, after compilation you need to restart the Apache Tomcat in order to
reflect the changes.
·
·
No comments:
Post a Comment