java2db

Jsp-Servlet example in Eclipse,NetBeans and MyEclipse



Jsp-Servlet exampleJSP (JavaServer Page) :

Jsp-Servlet 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 example Jsp can call custom java classes (taglibs) with HTML-like tags.
Jsp-Servlet example Separates both dynamic content(java code) and presentation(HTML code) of a Web page.

 

Jsp-Servlet exampleServlet :

Jsp-Servlet 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..) .

Jsp-Servlet example HTTP Request – Client request from a web browser to the server.
Jsp-Servlet example HTTP Response – Response from the server to the requested client.

 

Basic requirements are given below to run the Jsp-Servlet example .

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

 

Jsp-Servlet example Directory structure :

Eclipse :

 

NetBeans :

 

 

 

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 (JspServletApp.JspServletApp) attached to the servlet-name .

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

6. The doPost() method will execute.

7. Finally the response goes to the client window.

 

Jsp-Servlet example Jsp-Servlet example code :

The below example is a simple login form .It has two input fields (user id and password) and a submit button.

Jsp-Servlet example login.jsp

Jsp-Servlet example JspServletApp.java(servlet)

Jsp-Servlet example web.xml

Jsp-Servlet example success.jsp

Jsp-Servlet example fail.jsp

 

Output for Jsp-Servlet example in web browser  :
Connect PostgreSQL with Hibernate

On success logged in with valid credentials .

Connect PostgreSQL with Hibernate

If the credentials are wrong , the servlet returns fail.jsp  .

Connect PostgreSQL with Hibernate




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 )
   [will not be published]



^ <