java2db

Jsp,Servlet and JDBC integration example in Eclipse



Jsp/Servlets or JDBC is not an installable software.So add all required jar files to the libraries for Jsp,Servlet and JDBC integration .The basic requirements are given below.

Jsp,Servlet and JDBC integration exampleJSP (JavaServer Page) :

Jsp,Servlet and JDBC integration example JavaServer Page allows programmer to embed java code directly in the HTML code.So we can easily embed java code in web pages.
Jsp,Servlet and JDBC integration example Jsp can call custom java classes (taglibs) with HTML-like tags.
Jsp,Servlet and JDBC integration example Separates both dynamic content(java code) and presentation(HTML code) of a Web page.

 

 Servlet :

Jsp,Servlet and JDBC integration example A servlet is a server side Java class and it runs in a java-enabled servers.It can handle HTTPrequest and provides HTTP Response in the form of web pages (like HTML,JSP,JSF..) .

HTTP Request – Client request from a web browser to the server.
Jsp,Servlet and JDBC integration example HTTP Response – Response from the server to the requested client.

 

JDBC (Java Database Connectivity) :
Jsp-Servlet-JDBC integration example JDBC  is an API (Application programming interface) is used to write java programs to connect to a ….database and perform various operations.
Jsp-Servlet-JDBC integration example A valid URL(Uniform Resource Locator),username and password are required to connect to a ….database.
Jsp-Servlet-JDBC integration example URL Database type+IP+port+Database name(Ex : jdbc:oracle:thin:@//localhost:1521/XE).

In the below example , we used Oracle database.

 

Basic requirements for Jsp,Servlet and JDBC integration .

Softwares :
Java (Download).
Oracle Database (Download).
GlassFish server (Download).
Eclipse IDE (Download).
NetBeans IDE (Download).
Jar files:
javax.servlet.jar (Download).
javax.servlet.jsp.jar (Download).
ojdbc14.jar (Download).
Source files :
login.jsp
loginServlet.java
web.xml
success.jsp
fail.jsp

 

 

Create Dynamic Web Project in Eclipse IDE:

Go to  file > new > Dynamic Web Project like below.
Jsp-Servlet-JDBC integration example

Enter the name of the project (Ex : jsp-servlet-jdbc).
Jsp-Servlet-JDBC integration example

click finish and copy all the files(.jsp, .java , .jar)  to the appropriate locations like below directory structure.

Jsp-Servlet-JDBC integration example

 

 

Jsp-Servlet-JDBC integration example

1. Web-client request comes to the Web-server , First it looks for the web.xml in the web-application ….directory structure and check the url-pattern (/loginServlet).

2. It identifies the servlet-name (In our example it is JspServletApp) .

3. It checks for the exact match of the servlet-name (JspServletApp) inside the <servlet> tag.

4. Now it will go to the servlet-class (loginServlet.loginServlet) attached to the servlet-name .

5. From there it looks for the servlet class file (JspServletApp.class) to execute .

6. The doPost() method sends request to the database with a SQL statement.

7. The database executes the SQL statement and sends back the result.

8. Finally the response goes to the client window.

 

Example code for the Jsp,Servlet and JDBC integration (login application) :

login.jsp

loginServlet.java

web.xml

success.jsp

failure.jsp

Execution :

Jsp-Servlet-JDBC integration example

Jsp-Servlet-JDBC integration example




Related Posts :
How to Connect to Oracle from Liferay portlet ( Java Liferay and Oracle integration )
How to Connect Liferay 7 to PostgreSQL ( Java Liferay portlet and PostgreSQL integration )
Kill or invalidate session using session id ( concurrent login )
Jsp , struts 2 example in eclipse (Struts login application )
Servlet Filter ( Request and Response filters in servlets ) example
URL rewriting in servlets ( Servlet session tracking )
Servlet Cookies ( Servlets session tracking with cookie )
Hidden form field in servlets ( Servlet session tracking )
   [will not be published]



^ <