Home Jsp Introduction to JSP


Share on Google+Share on Google+

Introduction to JSP

Introduction to JSP Introduction to JSP Java Server Pages or JSP for short is Sun's solution for developing dynamic web sites. JSP provide excellent server side scripting support for creating database driven web applications. JSP enable the

JSP Tutorials - Writing First JSP


Java Server Pages or JSP for short is Sun's solution for developing dynamic web sites. JSP provide excellent server side scripting support for creating database driven web applications. JSP enable the developers to directly insert java code into jsp file, this makes the development process very simple and its maintenance also becomes very easy.  JSP pages are efficient, it loads into the web servers memory  on receiving the request very first time and the subsequent calls are served within a very short period of time. 

  In today's environment most web sites servers dynamic pages based on user request. Database is very convenient way to store the data of users and other things. JDBC provide excellent database connectivity in heterogeneous database environment. Using JSP and JDBC its very easy to develop database driven web application. 

   Java is known for its characteristic of "write once, run anywhere." JSP pages are platform independent. Your port your .jsp pages to any platform.   

Installing JSP

First of all download JavaServer Web Development Kit (JSWDK1.0.1) from http://java.sun.com/products/servlet/download.html. JSWDK comes with full documentation and it's very easy to install, so the installation process is not mentioned here. The JSWDK is the official reference implementation of the servlet 2.1 and JSP 1.0 specifications. It is used as a small stand-alone server for testing servlets and JSP pages before they are deployed to a full Web server that supports these technologies. It is free and reliable, but takes quite a bit of effort to install and configure.

Other Servers that support JSP

  • Apache Tomcat.
    Tomcat is the official reference implementation of the servlet 2.2 and JSP 1.1 specifications. It can be used as a small stand-alone server for testing servlets and JSP pages, or can be integrated into the Apache Web server. 
  • Allaire JRun.
    JRun is a servlet and JSP engine that can be plugged into Netscape Enterprise or FastTrack servers, IIS, Microsoft Personal Web Server, older versions of Apache, O?Reilly?s WebSite, or StarNine WebSTAR.
  • New Atlanta?s ServletExec.
    ServletExec is a fast servlet and JSP engine that can be plugged into most popular Web servers for Solaris, Windows, MacOS, HP-UX and Linux. You can download and use it for free, but many of the advanced features and administration utilities are disabled until you purchase a license.
  • Gefion's LiteWebServer (LWS). LWS is a small free Web server that supports servlets version 2.2 and JSP 1.1.
  • GNU JSP. free, open source engine that can be installed on apache web server.
  • PolyJSP. PolyJsp is based on XML/XSL and has been designed to be extensible. Now supports WebL  
  • JRUN. Available for IIS server.
  • WebSphere. IBM's WebSphere very large application server now implements JSP.


Developing first JSP

Java Server Pages are save with .jsp extension. Following code which generates a simple html page. 

Execute the example. <html>
First JSP page.</title>
<p align=
"center"><font color="#FF0000" size="6"><%="Java Developers Paradise"%></font></p>
<p align=
"center"><font color="#800000" size="6"><%="Hello JSP"%> </font></p>
  In jsp java codes are written between '<%' and '%>' tags. So it takes the following form : <%= Some Expression %> In this example we have use 
  <%="Java Developers Paradise"%>


Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 23, 2004

Ask Questions?    Discuss: Introduction to JSP   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
dharmendra singh bora
May 14, 2011

name dharmendra singh bora,job data analyst in gbpuat pantnagar,
June 8, 2011
How to run jsp programs?

plz tell me how to run jsp programs...
July 7, 2011

hi i m new to dis. i ple send execution process of the jsp to my mail.
July 11, 2011
execution of jsp

iam confused while executing jsp in internet explorer . if my jsp program is saved as myfirstjsp.jsp then where do i save it. if i save it in this path C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\myweb\myfirstjsp.jsp then while executing in internet explorer if i give this path http://localhost:8080/myfirstpage then it is not executing instead it mentions the requested resource(myfirstjsp) is not available . so please help me.
July 6, 2011

in java programs we write user defined package for ex package info.student; public class Bill{ public static void main(String ar[]){ //code } } as like above program how to write user defined package in jsps. please reply.
July 6, 2011

how to write user defined exceptions in java
July 6, 2011

how to retrieve date from html form and how to store in database server in servlets.
v raj
August 17, 2011

Daffar Pandey
June 14, 2013
where to write jsp

Where to execute jsp
August 27, 2011
learn jsp

i am not study basic of jsp
December 8, 2011

December 30, 2011

January 26, 2012

The diffences between servlet and jsp
January 11, 2013

February 7, 2012
jsp in html

i want all tags in jsp in html language
March 5, 2012
facing database connection problem

when i connect jsp page to mysql through (import) con.java, i am getting..org.apache.jasper.JasperException: Unable to compile class for JSP An error occurred at line: -1 in the jsp file: null Generated servlet error: [javac] Compiling 1 source file C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\_\org\apache\jsp\gasagency\register_jsp.java:6: package agency does not exist import agency.*; ^ 1 error org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351) org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415) org.apache.jasper.compiler.Compiler.compile(Compiler.java:458) org.apache.jasper.compiler.Compiler.compile(Compiler.java:439) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:553) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) plz reply soon
Anbu Raja
March 22, 2012
Need Notes

I need full notes for JSP and XML
robin poulose
April 15, 2012
code not executed

http://www.mycgiserver.com/~jdbc/myfirstpage.jsp page not found error 404 not running!!
Aniket Patil
April 20, 2012
for advance java program

please send me steps how to run program
May 24, 2012

June 1, 2012
hi pujitha!!

<html> <head> <link href="calendar.css" rel="stylesheet" type="text/css"> <script src="calendar.js" type="text/javascript"></script> <script type="text/javascript"> function validate(form) { var c_emp_name=/^[A-Za-z ]{3,25}$/; var c_emp_id=/^[0-9]{5}$/; var c_des=/^[1-4]$/; var c_dept_name=/^[1-9]{1}$/; var c_head_id=/^[0-9]{5}$/; var c_sal=/^[1-5]$/; var c_email=/^[A-Za-z0-9_@.]{5,20}$/; var c_phone=/^[0-9]{10}$/; var c_address=/[A-za-z0-9 ]{5,50}$/; var c_Q1=/[A-za-z0-9 ]{5,50}$/; var c_exp=/[0-9]{1,2}$/; var c_user_id=/[A-Za-z0-9_]{5,15}$/; var c_password=/[A-za-z0-9]{5,15}$/; var c=/^[A-Y]{1}$/; var emp_name=form.emp_name.value; var emp_id=form.emp_id.value; var DOB=form.DOB.value; var sex=form.sex.value; var des=form.des.value; var dept_drop=form.dept_name.value; var head_id=form.head_id.value; var sal=form.sal.value; var email=form.email.value; var phone=form.phone.value; var DOJ=form.DOJ.value; var address=form.address.value; var Q1=form.Q1.value; var exp=form.exp.value; var user_id=form.user_id.value; var password=form.password.value; var d=c; if(!c_emp_name.test(emp_name)) { alert("Enter a valid Employee name"); c='Z'; } if(!c_emp_id.test(emp_id)) { alert("Enter a valid Employee id"); c='Z'; } if(!c_des.test(des)) { alert("Select a valid Desgination"); c='Z'; } if(!c_dept_name.test(dept_drop)) { alert("Enter a valid department id"); c='Z'; } if(!c_head_id.test(head_id)) { alert("Enter a valid Head_id"); c='Z'; } if(!c_sal.test(sal)) { alert("Select a valid Amount"); c='Z'; } if(!c_email.test(email)) { alert("Enter a valid email_ID"); c='Z'; } if(!c_phone.test(phone)) { alert("Enter a valid Phone number"); c='Z'; } if(!c_address.test(address)) { alert("Enter a valid Address"); c='Z'; } if(!c_Q1.test(Q1)) { alert("Enter a valid Qualification"); c='Z'; } if(!c_exp.test(exp)) { alert("Enter a valid experience"); c='Z'; } if(!c_user_id.test(user_id)) { alert("Enter a valid user_id"); c='Z'; } if(!c_password.test(password)) { alert("Enter a valid password"); c='Z'; } if(!c.test(d)) { alert("Form Submitted successfully"); } } </script> </head> <body> <h1>Creating accounts for Faculty</h1> <form name="form" method="post" action="faccount.jsp" style="padding:5px;" onsubmit="return validate(this)"> <p> <label>Faculty Name: </label> <input name="emp_name" type="text" class="txt" id="emp_name" size="20"> </p> <p> <label>Employee ID: </label> <input name="emp_id" type="text" class="txt" id="emp_id" size="5"> </p> <p> <label>Date of Birth: </label> <input name="DOB" type="text" class="txt" id="DOB"> <script type="text/javascript"> calendar.set("DOB"); </script> </p> <p> <label>Gender: </label> <input type="radio" name="sex" value="M" checked="default" /> Male <input type="radio" name="sex" value="F" /> Female</p> <p> <label>Designation: </label> <select name="des" class="txt" id="des"> <option value="">--</option> <option value="1">Lecturer</option> <option value="2">Ass.Professor</option> <option value="3">Professor</option> <option value="4">Head of the department</option> </select> </p> <p><label>Department Name:</label> <select name="dept_name" class="txt" id="dept_name"> <option value="">--</option> <option value="1">CSE</option> <option value="2">IT</option> <option value="3">ECE</option> <option value="4">EIE</option> <option value="5">EEE</option> <option value="6">CIVIL</option> <option value="7">MECHANICAL</option> <option value="8">BIO-TECH</option> <option value="9">MMM</option> </select> </p> <p> <label>Head ID: </label> <input name="head_id" type="text" class="txt" id="head_id" size="5"> </p> <p> <label>Date of Joining: </label> <input name="DOJ" type="text" class="txt" id="DOJ"> <script type="text/javascript"> calendar.set("DOJ"); </script> </p> <p><label>Salary:</label> <select name="sal" class="txt" id="sal"> <option value="">--</option> <option value="1">15000</option> <option value="2">25000</option> <option value="3">40000</option> <option value="4">60000</option> <option value="5">90000</option> </select> </p> <p><label>Email:</label> <input name="email" type="text" class="txt" id="email"> </p> <p><label>Phone Number:</label> <input name="phone" type="text" class="txt" id="phone" size="10"> </p> <p><label>Address:</label> <textarea name="address" type="text" class="txt" id="address" size="50" rows="2" columns="25"></textarea> </p> <p><label>Qualification:</label> <input name="Q1" type="text" class="txt" id="Q1" size="50"> </p> <p><label>Experience:</label> <input name="exp" type="text" class="txt" id="exp" size="2"> </p> <p><label>User ID:</label> <input name="user_id" type="text" class="txt" id="user_id" size="15"> </p> <p><label>Password:</label> <input name="password" type="text" class="txt" id="password" size="15"> </p> <p> <input type="submit" name="Submit" value="Submit"> <input type="reset" name="reset" value="Reset"> </p> </form> </body> </html> <-------------Jsp file------------------> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import ="java.sql.*" %> <%@ page import ="javax.sql.*" %> <%@ page import ="java.sql.DriverManager" %> <%@ page import ="java.sql.Connection" %> <%@ page import ="java.sql.SQLException" %> <% String emp_name=request.getParameter("emp_name"); String emp_id=request.getParameter("emp_id"); String DOB=request.getParameter("DOB"); String gender=request.getParameter("sex"); String designation=request.getParameter("des"); String email=request.getParameter("email"); String phone=request.getParameter("phone"); String address=request.getParameter("address"); String head_id=request.getParameter("head_id"); String Q1=request.getParameter("Q1"); String dept_drop=request.getParameter("dept_name"); String date_join=request.getParameter("DOJ"); String exp=request.getParameter("exp"); String salary=request.getParameter("sal"); String faculty_check="1"; String Q2=""; String Q3=""; String Q4=""; String photo=""; String userid=request.getParameter("user_id"); String password=request.getParameter("password"); String id=request.getParameter("emp_id"); String usertype="2"; Class.forName("com.mysql.jdbc.Driver"); java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root",""); Statement st= con.createStatement(); ResultSet rs1=st.executeQuery("select dept_ID,head_id from department where dept_drop='"+dept_drop+"'"); rs1.next(); String dept_id=rs1.getString(1); String x=rs1.getString(2); String sql=("INSERT INTO employee VALUES('"+emp_id+"','"+emp_name +"','"+faculty_check+"','"+DOB+"','"+gender+"','"+designation+"','" +email+"','"+phone+"','"+address+"','"+head_id+"','"+Q1+"','"+Q2+"','"+Q3+"','"+Q4+ "','"+dept_id+"','"+date_join+"','"+exp+"','"+salary+"','"+photo+"')"); st.executeUpdate(sql); String sqll=("INSERT INTO login_details VALUES('"+userid+"','"+password+"','"+usertype+"','"+id+"')"); st.executeUpdate(sqll); String sq=("UPDATE department SET head_id='"+head_id+"' WHERE dept_drop='"+dept_drop+"'"); st.execute(sq); con.close(); %> END
astha jain
June 8, 2012

please give the explanations sequentially to the example given above...... so that the user could also get the knowledge of running the program accurately.............
June 15, 2012

its very helpful to learn the basics of jsp.....
July 3, 2012

i need a ajax code for updating the multiple values in the form.dynamically to display the value in browser window from the web server
July 9, 2012

Write a program using JSP that enables any student to change the medium of instruction of his/her programme of study. Make necessary assumptions.
July 27, 2012
Good One

THis is good tutoril i have found here..! THNKS
Arul velanganni
September 6, 2012

how to develop the program knowledge.how to learn the java in tutorial.
kumar gaurav
September 11, 2012
java server page creation

December 15, 2012

Maruthi Reddy
April 2, 2013

sir, JSP better than Servlet or not?