java2db

Jsp , Servlet and JDBC login application example in NetBeans



Jsp Servlet and JDBC technologies are fairly easy to learn, and they bring the Write Once, Run Anywhere paradigm to web applications.These are easily maintainable and reusable. Jsp , Servlet and JDBC login application require additional jar files to communicate with database.

Jsp,Servlet and JDBC login application in NetBeansJSP (JavaServer Page) :

Jsp,Servlet and JDBC login application in NetBeans It allows programmer to combined java code directly in the HTML code.So it is easy to embed java code in web pages.
Jsp,Servlet and JDBC login application in NetBeans Jsp can call custom java classes (taglibs) with HTML-like tags.
Jsp,Servlet and JDBC login application in NetBeans It Separates both dynamic content(java code) and presentation(HTML code) of a Web page.

 

 Servlet :

Jsp,Servlet and JDBC login application in NetBeans A servlet is a server side Java class (.class) and it runs in a java-enabled servers.It receives HTTPrequest and sends back the HTTP Response to the clients (in HTML,JSP,JSF..) .

HTTP Request – Client sends request to the web/application server (http://).
Jsp,Servlet and JDBC login application in NetBeans HTTP Response – Web/Application server sends back the response to the requested clients.

 

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 like oracle,DB2,MySql.
Jsp-Servlet-JDBC integration example A valid URL(Uniform Resource Locator),username and password are required to connect to a ….database.
Jsp,Servlet and JDBC login application in NetBeans 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 login application .

Softwares :
Java  (Download).
Oracle Database  (Download).
GlassFish server  (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 a web project in NetBeans IDE :
Jsp-Servlet-JDBC integration example Go to file , select the New Project.
Jsp-Servlet-JDBC integration example
Jsp-Servlet-JDBC integration example Enter the name of the Web project.
Jsp-Servlet-JDBC integration example
Jsp-Servlet-JDBC integration example Select the Web/Application server to run our application.
Jsp-Servlet-JDBC integration example
Jsp-Servlet-JDBC integration example Finally click finish button.
Jsp-Servlet-JDBC integration example
Jsp-Servlet-JDBC integration example Copy all the files (.jsp ,  .java ,  .jar ) in the specific folders . The complete directory structure given below .
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(WEB-INF) 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 like a web page.

 

Example 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 :
Call database in Jsp (Access Oracle , MySQL , PostgerSQL ,Db2 from Jsp)
How to integrate Jsp , Struts 2 and hibernate 4 ( Login example )
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 )

Comments

  1. tolssekiJut says:

    Hello! I really like your blog! Continue to write more! Very interesting!

   [will not be published]



^ <