{"id":23870,"date":"2015-06-09T11:00:29","date_gmt":"2015-06-09T08:00:29","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=23870"},"modified":"2015-08-02T17:26:03","modified_gmt":"2015-08-02T14:26:03","slug":"jsp-tutorial-beginners","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/","title":{"rendered":"JSP Tutorial For Beginners"},"content":{"rendered":"<p>JSP is a server side technology which helps to create dynamic, platform-independent java web applications and is mainly used for implementing the presentation layer. In this tutorial, we will look into the essentials of the JSP technology with illustrating some simple code. <\/p>\n<p>As a prerequisite of this post, we assume you have knowledge what is HTML, web server and Java programming language and how web application work over HTTP. <\/p>\n<h2>1. What is JSP?<\/h2>\n<p>Java Server Pages (JSP) code is likely HTML with bits of Java code in it. Very basically, in order to create a JSP code, you can take any existing HTML page and change its extension to &#8220;.jsp&#8221; instead of &#8220;.html&#8221;. Then you can put Java code in it with some structures called <b>Scriptlet, Directive, Expression<\/b>. In the code below, the JSP file shows the current time:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;html&gt;\r\n\t&lt;body&gt;\r\n\t\tThe current time is &lt;%= new java.util.Date() %&gt;\r\n\t&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>In the other code, we make some calculations:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;html&gt;\r\n    &lt;%\r\n\t   int a = 5;\r\n\t   int b = 8;\t\r\n\t%&gt; \r\n\t&lt;body&gt;\r\n\t\tThe first number is : &lt;%= a %&gt; &lt;br\/&gt;\r\n\t\tThe second number is : &lt;%= b %&gt; &lt;br\/&gt;\r\n\t\tThe sum is : &lt;%= ( a + b ) %&gt; &lt;br\/&gt;\r\n\t&lt;\/body&gt;\r\n&lt;\/html&gt; \r\n<\/pre>\n<p>As you see, in a JSP file, HTML and Java code are mixed. You can also access to the entire family of Java APIs, including the JDBC API to access enterprise databases in the JSP file. The main structure is the HTML. But with Java in it, you can access the wide-ranging Java APIs and libraries. With this flexible nature, Web Application Programmers can concentrate on how to process the information in the presentation layer ( HTML, GUI part ).<\/p>\n<p>JSP is an extension of <b>Servlets<\/b> and every JSP page first gets converted into servlet by JSP container before processing the client\u2019s request. The Servlet is older Java technology than JSP. It consists of pure Java code and holds the capabilities of the servers, HTML protocol. The Servlet code enables to have HTML codes in it. But this process is cumbersome and error prone, when it comes to writing a complex HTML response. JSP helps in this situation and provide us to write normal HTML page and include our java code only where it\u2019s required.<\/p>\n<p>Now, let&#8217;s see the principal JSP elements and try to explain them briefly. <\/p>\n<h3>1.1 JSP Syntactic Elements<\/h3>\n<p>In a JSP file, the Java code is usually written in a <b>Scriptlet tags<\/b> with a format like below:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;% Java code %&gt;\r\n<\/pre>\n<p>A scriptlet can contain any number of Java statements, variable or method declarations that are accessible from anywhere within the JSP page.<\/p>\n<p>Variable or method declarations can be also written between the <b>Declaration tags<\/b> ( <code>&lt;%! %&gt;<\/code> ):<\/p>\n<pre class=\"brush:xml\">\r\n&lt;%!  \r\n   int a, b;\r\n   public int sum( int i1, int i2 ) { return i1 + i2; }\r\n%&gt;\r\n<\/pre>\n<p>JSP <b>Expression tag<\/b> ( <code>&lt;%= %&gt;<\/code> ) contains Java statement that is evaluated, converted to a String and written to the output stream of the response. For example, to write the content of the variable &#8220;name&#8221; to the screen, we can use <code>&lt;%=name%&gt;<\/code>. The scriptlet equivalent of this: <code>&lt;% out.print( name ); %&gt;<\/code>. Please note that in the expression tag, you don&#8217;t have to put semicolon (;) at the end of the line, but in the scriptlet you do.<\/p>\n<p>Following is the syntax of <b>JSP comments<\/b>:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;%-- JSP comment. Ignored by the JSP engine. --%&gt;\r\n<\/pre>\n<h3>1.2 JSP Implicit Objects <\/h3>\n<p>JSP Implicit Objects are the useful coding objects that the JSP Container makes available to developers in every JSP page. We can call them directly in scriptlets without any declaration. There are 9 JSP implicit objects. We show them and their counterpart Servlet and Java objects below:<\/p>\n<table>\n<thead>\n<tr>\n<th><font style=\"color:#A81510;font-weight:bold\">Object<\/font><\/th>\n<th><font style=\"color:#A81510;font-weight:bold\">Type<\/font><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>request<\/td>\n<td>javax.servlet.http.HttpServletRequest<\/td>\n<\/tr>\n<tr>\n<td>response<\/td>\n<td>javax.servlet.http.HttpServletResponse<\/td>\n<\/tr>\n<tr>\n<td>pageContext<\/td>\n<td>javax.servlet.jsp.PageContext<\/td>\n<\/tr>\n<tr>\n<td>session<\/td>\n<td>javax.servlet.http.HttpSession<\/td>\n<\/tr>\n<tr>\n<td>application<\/td>\n<td>javax.servlet.ServletContext<\/td>\n<\/tr>\n<tr>\n<td>out<\/td>\n<td>javax.servlet.jsp.JspWriter<\/td>\n<\/tr>\n<tr>\n<td>config<\/td>\n<td>javax.servlet.ServletConfig<\/td>\n<\/tr>\n<tr>\n<td>page<\/td>\n<td>java.lang.Object<\/td>\n<\/tr>\n<tr>\n<td>exception<\/td>\n<td>java.lang.Throwable<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre class=\"brush:xml\">\r\n&lt;% out.print( \"Hello \" + request.getParameter( \"username\" ) ); %&gt;\r\n<\/pre>\n<p>In this code, two implicit objects ( out, request ) are used. The &#8220;username&#8221; parameter is fetched from the <b>request<\/b> object and after concatenating the &#8220;Hello&#8221; word, printed to the client with the <b>out<\/b> implicit object.<\/p>\n<h3>1.3 JSP Directives <\/h3>\n<p>JSP directives are messages and instructions to the JSP container, telling it how to translate a JSP page into the corresponding Servlet. Directives have this syntax:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;% @ directive { attr=\u201dvalue\u201d }* %&gt;\r\n<\/pre>\n<p>There are three directives. Here is the list:<\/p>\n<table>\n<thead>\n<tr>\n<th><font style=\"color:#A81510;font-weight:bold\">Directive<\/font><\/th>\n<th style=\"width:330px\"><font style=\"color:#A81510;font-weight:bold\">Sample Syntax<\/font><\/th>\n<th><font style=\"color:#A81510;font-weight:bold\">Description<\/font><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>page<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;%@ page import=&#8221;java.util.*,java.text.*&#8221; %&gt;<\/font><br \/>( Imports other Java libraries into the JSP page )<\/td>\n<td>The page directive defines a number of page dependent properties and communicates<br \/>\nthese to the JSP container. Page directive attribute list is: language, extends, import, session, buffer, autoFlush, isThreadSafe, info, errorPage, isErrorPage, contentType, pageEncoding, isELIgnored, deferredSyntaxAllowedAsLiteral, trimDirectiveWhitespaces. <\/td>\n<\/tr>\n<tr>\n<td>include<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;%@ include file=&#8221;otherPage.jsp&#8221; %&gt;<\/font><br \/>( Merge the content of the other jsp file )<\/td>\n<td>The include directive is used to substitute text and\/or code at JSP page translation-time. This directive tells the container to insert the content of other files with the current JSP.<\/td>\n<\/tr>\n<tr>\n<td>taglib<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;%@ taglib uri=&#8221;\/WEB-INF\/c.tld&#8221; prefix=&#8221;c&#8221;%&gt;<\/font><br \/>( Declares the external taglib. Tablib uri can be an url address or tld tag library file path )<\/td>\n<td>The taglib directive in a JSP page declares that the page uses a tag library,<br \/>\nuniquely identifies the tag library using a URI and associates a tag prefix that will<br \/>\ndistinguish usage of the actions in the library<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>1.4 JSP Actions <\/h3>\n<p>JSP actions are the basically predefined functions based on XML syntax. They get the JSP container to do some behaviours, actions. They may affect the current out stream and use, modify and\/or create objects.<\/p>\n<p>The syntax for an Action element is:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;jsp:action_name attribute=\"value\" \/&gt;\r\n<\/pre>\n<p>Here is the list of the some JSP Actions:<\/p>\n<table>\n<thead>\n<tr>\n<th><font style=\"color:#A81510;font-weight:bold\">Action<\/font><\/th>\n<th><font style=\"color:#A81510;font-weight:bold\">Description<\/font><\/th>\n<th style=\"width:350px\"><font style=\"color:#A81510;font-weight:bold\">Sample Code<\/font><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>jsp:useBean<\/td>\n<td>Associates an instance of a Java programming language object. Try to find an existing java object. If the object is not found it will attempt to create the object using attributes.<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;jsp:useBean id=&#8221;connection&#8221; class=&#8221;com.myapp.Connection&#8221;\/&gt;<\/font><\/td>\n<\/tr>\n<tr>\n<td>jsp:setProperty<\/td>\n<td>Sets the values of properties in a bean. Properties in a Bean can be set from one or more parameters in the request object, from a String constant, or from a computed request-time expression.<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;jsp:setProperty name=&#8221;user&#8221; property=&#8221;userobj&#8221; param=&#8221;username&#8221; \/&gt;<\/font><\/td>\n<\/tr>\n<tr>\n<td>jsp:getProperty<\/td>\n<td>Places the value of a bean instance property, converted to a String, and print it. This simply means inserting it into the implicit &#8220;out&#8221; object.<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;jsp:getProperty name=\u201duser\u201d property=\u201dname\u201d \/&gt;<\/font><\/td>\n<\/tr>\n<tr>\n<td>jsp:include<\/td>\n<td>Provides for the inclusion of static and dynamic<br \/>\nresources in the same context as the current page.<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;jsp:include page=\u201d\/static\/copyright.html\u201d\/&gt;<\/font><\/td>\n<\/tr>\n<tr>\n<td>jsp:forward<\/td>\n<td>Allows the runtime dispatch of the current<br \/>\nrequest to a static resource, a JSP page or a Java servlet class in the same context<br \/>\nas the current page.<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;jsp:forward page='&lt;%= whereTo %&gt;&#8217; \/&gt;<\/font><\/td>\n<\/tr>\n<tr>\n<td>jsp:param<\/td>\n<td>This action element is used to provide key\/value information. This element<br \/>\nis used in the jsp:include, jsp:forward, and jsp:params elements.<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;jsp:param name=&#8221;name&#8221; value=&#8221;value&#8221; \/&gt;<\/font><\/td>\n<\/tr>\n<tr>\n<td>jsp:plugin<\/td>\n<td>This tag is replaced by either an &lt;object&gt; or &lt;embed&gt; tag, as<br \/>\nappropriate for the requesting user agent, and emitted into the output stream of the<br \/>\nresponse.<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;jsp:plugin type=&#8221;applet&#8221; code=&#8221;Molecule.class&#8221; codebase=&#8221;\/html&#8221;&gt;&lt;jsp:params&gt;&#8230;&lt;\/jsp:params&gt;&lt;\/jsp:plugin&gt;<\/font><\/td>\n<\/tr>\n<tr>\n<td>jsp:attribute<\/td>\n<td>Defines an attribute value for another JSP action element instead of in<br \/>\nthe value of an XML attribute.<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;jsp:attribute name=&#8221;even&#8221;&gt;<\/font><\/td>\n<\/tr>\n<tr>\n<td>jsp:text<\/td>\n<td>This action can be used to enclose template data in a JSP page, a JSP document,<br \/>\nor a tag file.<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;jsp:text&gt;This is some content&lt;\/jsp:text&gt;<\/font><\/td>\n<\/tr>\n<tr>\n<td>jsp:output<\/td>\n<td>This action is used to modify some properties of the output of a JSP document<br \/>\nor a tag file.<\/td>\n<td><font style=\"font-family:courier,verdana;color:blue\">&lt;jsp:output xmlns:jsp=\u201dhttp:\/\/java.sun.com\/JSP\/Page\u201d omit-xml-declaration=\u201dtrue\u201d\/&gt;<\/font><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>1.5 JSP &#8211; Standard Tag Library (JSTL) <\/h3>\n<p>JSP Standard Tag Library (JSTL) is a set of useful tags to simplify the JSP development. It provides tags to control the JSP page behavior, iteration and control statements, internationalization tags, and SQL tags. JSTL is part of the Java EE API and included in most servlet containers. There are five groups of JSTL: core tags, sql tags, xml tags, internationalization tags and functions tags.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>In the code snippet below, there is a simple loop coded with JSTL. Without any tag library or tags, we can write the counterpart code with scriptlets that contain Java code in it. But external tag libraries provide more simple and useful capabilities to us. We can do more with writing less.<\/p>\n<pre class=\"brush:xml\">\r\n&lt;%@ taglib uri=\"http:\/\/java.sun.com\/jsp\/jstl\/core\" prefix=\"c\" %&gt;  \r\n&lt;c:forEach var=\"number\" begin=\"5\" end=\"10\"&gt;  \r\n   &lt;c:out value=\"${number}\"&gt;&lt;\/c:out&gt;  \r\n&lt;\/c:forEach&gt;  \r\n<\/pre>\n<h3>1.6 JSP &#8211; Expression Language (EL) <\/h3>\n<p>JSP Expression Language (EL) simplifies to access application data stored in JavaBeans properties. EL also includes arithmetic, relational and logical operators. There are two constructs to represent EL expressions: ${expr} and #{expr}. EL also has its own operators, keywords and implicit objects.<\/p>\n<p>The &#8220;param&#8221; implicit object holds request parameters as strings. In the code below, EL statement <code>${param.name}<\/code> retrieves the &#8220;name&#8221; parameter of the request. In the second line, you see the plus operator evaluates the addition calculations. <\/p>\n<pre class=\"brush:xml\">\r\n&lt;h1&gt;Welcome ${param.name}&lt;\/h1&gt;\r\n&lt;p&gt;The result is ${a + b}&lt;\/p&gt;\r\n<\/pre>\n<h2>2. Overview<\/h2>\n<p>In our example, you see a simple issue tracking management web application with a single JSP page that contains the issue list and a form to insert a new issue. When you submit a new issue, this issue is appended to the list below with &#8216;OPEN&#8217; status and &#8216;current time&#8217; created date by default. In the list, the status of the each issue item can be changed by the buttons in its row. &#8216;CLOSE&#8217; status issues are not listed and when you click on the close, the item you close is removed from the list. The background colors of the rows depend on their status. The rows of the &#8216;OPEN&#8217; status issues are pink, &#8216;FIX&#8217; status issues are green. <\/p>\n<p><figure id=\"attachment_24058\" aria-describedby=\"caption-attachment-24058\" style=\"width: 717px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/jspexample_img1.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/jspexample_img1.jpg\" alt=\"Jsp Application Appearance\" width=\"717\" height=\"682\" class=\"size-full wp-image-24058\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/jspexample_img1.jpg 717w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/jspexample_img1-300x285.jpg 300w\" sizes=\"(max-width: 717px) 100vw, 717px\" \/><\/a><figcaption id=\"caption-attachment-24058\" class=\"wp-caption-text\">Jsp Application Appearance<\/figcaption><\/figure><\/p>\n<p>Our preferred IDE is Eclipse. We use &#8216;Maven&#8217; for the dependency management. We create a dynamic web application and deploy it into the Tomcat server. Before, I have explained how to create a Maven dynamic web application in the Eclipse, how to define a &#8220;Tomcat&#8221; server and add the application to it in my other example. You can examine: <a href=\"http:\/\/examples.javacodegeeks.com\/enterprise-java\/logback\/logback-mapped-diagnostic-contexts-mdc-example\/\">Logback Mapped Diagnostic Contexts (MDC) Example<\/a><\/p>\n<p>We add three dependencies to the Maven &#8220;pom.xml&#8221; file:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Dependencies in the pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">\r\n\t&lt;dependencies&gt;\r\n\t\t&lt;dependency&gt;\r\n    \t\t&lt;groupId&gt;javax.servlet&lt;\/groupId&gt;\r\n    \t\t&lt;artifactId&gt;javax.servlet-api&lt;\/artifactId&gt;\r\n    \t\t&lt;version&gt;3.1.0&lt;\/version&gt;\r\n    \t\t&lt;scope&gt;provided&lt;\/scope&gt;\r\n\t\t&lt;\/dependency&gt;\t\t\r\n\t\t&lt;dependency&gt;\r\n         &lt;groupId&gt;jstl&lt;\/groupId&gt;\r\n         &lt;artifactId&gt;jstl&lt;\/artifactId&gt;\r\n         &lt;version&gt;1.2&lt;\/version&gt;\r\n    \t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n    \t\t&lt;groupId&gt;com.h2database&lt;\/groupId&gt;\r\n    \t\t&lt;artifactId&gt;h2&lt;\/artifactId&gt;\r\n    \t\t&lt;version&gt;1.4.187&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\t\t\t\t\t\r\n\t&lt;\/dependencies&gt;\r\n<\/pre>\n<p>We keep the issue records in a <a href=\"http:\/\/www.h2database.com\/html\/main.html\" target=\"_blank\"><b>H2<\/b><\/a> memory database. We add &#8220;Standard Tag Library (JSTL)&#8221; jar file to the classpath. Because we use it in somewhere in the JSP code. We create two <b>Servlet<\/b>s classes, so in order to compile it in our environment, we add servlet-api as provided. Anyway jsp-api and servlet-api jar files are already exist in the Jsp Container ( Tomcat Server ). So after compilation, you do not need to put these files in your project package ( war, ear ). If you put different version of the jsp\/servlet jar files in the project package, probably you will get errors while deploying. For example, I executed this example in Tomcat 8. Apache Tomcat version 8.0 implements the Servlet 3.1 and JavaServer Pages 2.3 specifications from the Java Community Process. So I deliberately add the Servlet &#8220;3.1&#8221; version to the pom.xml file.  <\/p>\n<h2>3. Implementation<\/h2>\n<p>In a JSP application, putting all of the Java codes in the JSP pages is not a good practice. You should separate the presentation layer from the business logic. In this way, you can easily adapt the application to a new look without changing the infrastructural codes. <\/p>\n<p>As I mentioned before, we store the issue records in a H2 memory database. We put the database implementation codes in a new Java class, not in the JSP page. To keep simple dependency list, we choose pure JDBC approach for database access, not an ORM tool like Hibernate, or another helper framework like Spring JDBC. The code of our database access class &#8220;DbOperations&#8221; is below. We call it in the JSP page to perform the database layer executions. <\/p>\n<p><span style=\"text-decoration: underline\"><em>DbOperations.java<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false\">\r\n\r\npackage com.javacodegeeks.examples.jspexample.db;\r\n\r\nimport java.sql.Connection;\r\nimport java.sql.DriverManager;\r\nimport java.sql.PreparedStatement;\r\nimport java.sql.ResultSet;\r\nimport java.sql.SQLException;\r\nimport java.util.ArrayList;\r\nimport java.util.Date;\r\nimport java.util.List;\r\n\r\nimport com.javacodegeeks.examples.jspexample.db.entity.Issue;\r\n\r\npublic class DbOperations {\r\n\r\n\tprivate static DbOperations\ttheInstance\t= new DbOperations();\r\n\r\n\tprivate Connection\t\t\tconnection;\r\n\r\n\tprivate DbOperations() {\r\n\t\ttry {\r\n\t\t\tClass.forName( \"org.h2.Driver\" );\r\n\t\t\tconnection = DriverManager.getConnection( \"jdbc:h2:mem:testdb\", \"sa\", \"\" );\r\n\r\n\t\t\t\/\/ Create table\r\n\t\t\tfinal PreparedStatement ps = connection\r\n\t\t\t\t.prepareStatement( \"CREATE TABLE ISSUE( ID INT PRIMARY KEY auto_increment, TITLE VARCHAR, OPENEDBY VARCHAR, PRIORITY VARCHAR, STATUS VARCHAR DEFAULT 'OPEN', COMMENT VARCHAR, CREATE_DATE TIMESTAMP DEFAULT NOW() )\" );\r\n\t\t\tps.executeUpdate();\r\n\t\t} catch ( final ClassNotFoundException e ) {\r\n\t\t\te.printStackTrace();\r\n\t\t} catch ( final SQLException e ) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic static DbOperations getTheInstance() {\r\n\t\treturn theInstance;\r\n\t}\r\n\r\n\tpublic void addNewIssueRecord( final String title, final String openedBy, final String priority,\r\n\t\tfinal String comments ) {\r\n\r\n\t\ttry {\r\n\t\t\tfinal PreparedStatement ps = connection\r\n\t\t\t\t.prepareStatement( \"INSERT INTO ISSUE( TITLE, OPENEDBY, PRIORITY, COMMENT ) VALUES ( ?, ?, ?, ? )\" );\r\n\r\n\t\t\tps.setString( 1, title );\r\n\t\t\tps.setString( 2, openedBy );\r\n\t\t\tps.setString( 3, priority );\r\n\t\t\tps.setString( 4, comments );\r\n\r\n\t\t\tps.executeUpdate();\r\n\t\t} catch ( final SQLException e ) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n\r\n\tpublic List getAllIssues() {\r\n\r\n\t\tfinal List issueList = new ArrayList();\r\n\r\n\t\ttry {\r\n\t\t\tfinal PreparedStatement ps = connection\r\n\t\t\t\t.prepareStatement( \"SELECT ID, TITLE, OPENEDBY, PRIORITY, STATUS, COMMENT, CREATE_DATE FROM ISSUE\" );\r\n\r\n\t\t\tfinal ResultSet rs = ps.executeQuery();\r\n\r\n\t\t\twhile ( rs.next() ) {\r\n\r\n\t\t\t\tfinal Issue issue = new Issue();\r\n\r\n\t\t\t\tissue.setComments( rs.getString( \"COMMENT\" ) );\r\n\t\t\t\tissue.setCreateDate( new Date() );\r\n\t\t\t\tissue.setId( rs.getInt( \"ID\" ) );\r\n\t\t\t\tissue.setOpenedby( rs.getString( \"OPENEDBY\" ) );\r\n\t\t\t\tissue.setPriority( rs.getString( \"PRIORITY\" ) );\r\n\t\t\t\tissue.setStatus( rs.getString( \"STATUS\" ) );\r\n\t\t\t\tissue.setTitle( rs.getString( \"TITLE\" ) );\r\n\r\n\t\t\t\tissueList.add( issue );\r\n\t\t\t}\r\n\r\n\t\t} catch ( final SQLException e ) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\r\n\t\treturn issueList;\r\n\t}\r\n\r\n\tpublic void updateIssueRecord( final String id, final String newStatus ) {\r\n\t\ttry {\r\n\t\t\tfinal PreparedStatement ps = connection\r\n\t\t\t\t.prepareStatement( \"UPDATE ISSUE SET STATUS = ? WHERE ID = ?\" );\r\n\r\n\t\t\tps.setString( 1, newStatus );\r\n\t\t\tps.setInt( 2, Integer.parseInt( id ) );\r\n\r\n\t\t\tps.executeUpdate();\r\n\t\t} catch ( final SQLException e ) {\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>At the top of the JSP page, we place the &#8220;taglib&#8221; and &#8220;page&#8221; <b>JSP directives<\/b> to import the backend Java classes and Servlets in the application and JSTL tag libraries.<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;%@ taglib prefix=\"c\" uri=\"http:\/\/java.sun.com\/jsp\/jstl\/core\" %&gt;\r\n&lt;%@ taglib prefix=\"fmt\" uri=\"http:\/\/java.sun.com\/jsp\/jstl\/fmt\" %&gt;\r\n\r\n&lt;?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?&gt;\r\n&lt;%@ page language=\"java\" contentType=\"text\/html; charset=ISO-8859-1\"\r\n\tpageEncoding=\"ISO-8859-1\"%&gt;\r\n&lt;%@ page import=\"com.javacodegeeks.examples.jspexample.db.DbOperations\"%&gt;\r\n&lt;%@ page import=\"java.util.*\"%&gt;\r\n&lt;%@ page import=\"com.javacodegeeks.examples.jspexample.db.entity.*\"%&gt;\r\n<\/pre>\n<p><a href=\"http:\/\/getbootstrap.com\/\"><b>Bootstrap<\/b><\/a> is a popular HTML, CSS, and JS framework. It contains predefined css classes, icons that help the developers to form the gui look easily. We use it to build the jsp page appearance. The html codes that generate the &#8220;new issue form&#8221; are below:<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;div style=\"width: 500px; margin-left: 50px; margin-top: 20px;\"&gt;\r\n\r\n\t&lt;div class=\"col-md-12 col-sm-6 col-xs-12\"&gt;\r\n\r\n\t\t&lt;div class=\"panel panel-default\"&gt;\r\n\r\n\t\t\t&lt;div class=\"panel-heading clearfix\"&gt;\r\n\t\t\t\t&lt;i class=\"icon-calendar\"&gt;&lt;\/i&gt;\r\n\t\t\t\t&lt;h3 class=\"panel-title\"&gt;Add New Issue&lt;\/h3&gt;\r\n\t\t\t&lt;\/div&gt;\r\n\r\n\t\t\t&lt;div class=\"panel-body\"&gt;\r\n\t\t\t&lt;form id=\"issueForm\" method=\"post\"\r\n\t\t\t\tclass=\"form-horizontal row-border\" action=\"\/jspexample\/addIssue\"&gt;\r\n\r\n\t\t\t\t&lt;div class=\"form-group\"&gt;\r\n\t\t\t\t\t&lt;label class=\"col-md-3 control-label\"&gt;Title&lt;\/label&gt;\r\n\t\t\t\t\t&lt;div class=\"col-md-9\"&gt;\r\n\t\t\t\t\t\t&lt;input type=\"text\" name=\"title\" class=\"form-control\" \/&gt;\r\n\t\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\r\n\t\t\t\t&lt;div class=\"form-group\"&gt;\r\n\t\t\t\t\t&lt;label class=\"col-md-3 control-label\"&gt;Opened By&lt;\/label&gt;\r\n\t\t\t\t\t&lt;div class=\"col-md-6\"&gt;\r\n\t\t\t\t\t\t&lt;select class=\"form-control\" name=\"openedby\"&gt;\r\n\t\t\t\t\t\t\t&lt;option value=\"Bob\"&gt;Bob&lt;\/option&gt;\r\n\t\t\t\t\t\t\t&lt;option value=\"George\"&gt;George&lt;\/option&gt;\r\n\t\t\t\t\t\t\t&lt;option value=\"Ali\"&gt;Ali&lt;\/option&gt;\r\n\t\t\t\t\t\t&lt;\/select&gt;\r\n\t\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\r\n\t\t\t\t&lt;div class=\"form-group\"&gt;\r\n\t\t\t\t\t&lt;label class=\"col-md-3 control-label\"&gt;Priority&lt;\/label&gt;\r\n\t\t\t\t\t&lt;div class=\"col-md-6\"&gt;\r\n\t\t\t\t\t\t&lt;select class=\"form-control\" name=\"priority\"&gt;\r\n\t\t\t\t\t\t\t&lt;option value=\"High\"&gt;High&lt;\/option&gt;\r\n\t\t\t\t\t\t\t&lt;option value=\"Medium\"&gt;Medium&lt;\/option&gt;\r\n\t\t\t\t\t\t\t&lt;option value=\"Low\"&gt;Low&lt;\/option&gt;\r\n\t\t\t\t\t\t&lt;\/select&gt;\r\n\t\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\r\n\t\t\t\t&lt;div class=\"form-group\"&gt;\r\n\t\t\t\t\t&lt;label class=\"col-md-3 control-label\"&gt;Comments&lt;\/label&gt;\r\n\t\t\t\t\t&lt;div class=\"col-md-9\"&gt;\r\n\t\t\t\t\t\t&lt;textarea rows=\"6\" class=\"form-control\" name=\"comments\"&gt;&lt;\/textarea&gt;\r\n\t\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\r\n\t\t\t\t&lt;div class=\"form-group\"&gt;\r\n\t\t\t\t\t&lt;label class=\"col-md-3\"&gt;&lt;\/label&gt;\r\n\t\t\t\t\t&lt;div class=\"col-md-9\"&gt;\r\n\t\t\t\t\t\t&lt;input type=\"submit\" value=\"Submit\" \/&gt;\r\n\t\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\t\t\t&lt;\/form&gt;\r\n\t\t\t&lt;\/div&gt;\r\n\t\t&lt;\/div&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>The Html codes of the issue list are below. Later, we will discuss the fundamental lines and explain them.<\/p>\n<pre class=\"brush:xml;;wrap-lines:false\">\r\n\t&lt;%\r\n\t\tList&lt; Issue &gt; issueList = DbOperations.getTheInstance().getAllIssues();\t\r\n\t\tpageContext.setAttribute(\"issueList\", issueList);\t\t\r\n\t\t\r\n\t\tMap&lt; String, String &gt; issueColors = new HashMap&lt; String, String &gt;();\r\n\t\tissueColors.put( \"OPEN\", \"#E2C8C8\" );\r\n\t\tissueColors.put( \"FIX\", \"#C1E212\" );\r\n\t\t\r\n\t\tpageContext.setAttribute(\"issueColors\", issueColors );\r\n\t%&gt;\r\n\r\n\t&lt;div style=\"width: 800px; margin-left: 50px; margin-top: 30px;\"&gt;\r\n\r\n\t\t&lt;%\r\n\t\t\tif ( issueList.size() &gt; 0 ) {\r\n\t\t%&gt;\r\n\r\n\t\t&lt;div class=\"col-md-11\"&gt;\r\n\t\t\t&lt;div class=\"panel panel-default\"&gt;\r\n\r\n\t\t\t\t&lt;div class=\"panel-heading\"&gt;\r\n\t\t\t\t\t&lt;i class=\"icon-calendar\"&gt;&lt;\/i&gt;\r\n\t\t\t\t\t&lt;h3 class=\"panel-title\"&gt;Issue List&lt;\/h3&gt;\r\n\t\t\t\t&lt;\/div&gt;\r\n\t\t\t\t&lt;div class=\"panel-body\"&gt;\r\n\t\t\t\t\t&lt;table class=\"table table-hover col-md-11\"&gt;\r\n\t\t\t\t\t\t&lt;thead&gt;\r\n\t\t\t\t\t\t\t&lt;tr&gt;\r\n\t\t\t\t\t\t\t\t&lt;th class=\"col-md-2\"&gt;Title&lt;\/th&gt;\r\n\t\t\t\t\t\t\t\t&lt;th class=\"col-md-2\"&gt;Opened By&lt;\/th&gt;\r\n\t\t\t\t\t\t\t\t&lt;th class=\"col-md-1\"&gt;Priority&lt;\/th&gt;\r\n\t\t\t\t\t\t\t\t&lt;th class=\"col-md-2\"&gt;Create Time&lt;\/th&gt;\r\n\t\t\t\t\t\t\t\t&lt;th class=\"col-md-1\"&gt;Status&lt;\/th&gt;\r\n\t\t\t\t\t\t\t\t&lt;th class=\"col-md-1\"&gt;Fix&lt;\/th&gt;\r\n\t\t\t\t\t\t\t\t&lt;th class=\"col-md-1\"&gt;Close&lt;\/th&gt;\r\n\t\t\t\t\t\t\t\t&lt;th class=\"col-md-1\"&gt;Reopen&lt;\/th&gt;\r\n\t\t\t\t\t\t\t&lt;\/tr&gt;\r\n\t\t\t\t\t\t&lt;\/thead&gt;\r\n\t\t\t\t\t\t&lt;tbody&gt;\r\n\t\t\t\t\t\t\t&lt;c:forEach items=\"${issueList}\" var=\"item\"&gt;\r\n\t\t\t\t\t\t\t\t&lt;c:if test=\"${item.status ne 'CLOSE'}\"&gt;\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t&lt;tr style=\"background-color: ${issueColors[item.status]}\"&gt;\r\n\t\t\t\t\t\t\t\t\t\t&lt;td&gt;&lt;c:out value=\"${item.title}\"\/&gt;&lt;\/td&gt;\r\n\t\t\t\t\t\t\t\t\t\t&lt;td&gt;&lt;c:out value=\"${item.openedby}\"\/&gt;&lt;\/td&gt;\r\n\t\t\t\t\t\t\t\t\t\t&lt;td&gt;&lt;c:out value=\"${item.priority}\"\/&gt;&lt;\/td&gt;\r\n\t\t\t\t\t\t\t\t\t\t&lt;td&gt;&lt;fmt:formatDate value=\"${item.createDate}\" pattern=\"dd-MM-yyyy HH:mm\" \/&gt;&lt;\/td&gt;\r\n\t\t\t\t\t\t\t\t\t\t&lt;td&gt;&lt;c:out value=\"${item.status}\"\/&gt;&lt;\/td&gt;\r\n\t\t\t\t\t\t\t\t\t\t&lt;td&gt;&lt;input type=\"button\" &lt;c:if test=\"${item.status == 'FIX'}\"&gt; disabled=\"disabled\" &lt;\/c:if&gt; onclick=\"location.href = '\/jspexample\/updateIssue?id=&lt;c:out value=\"${item.id}\"\/&gt;&amp;newStatus=FIX'\" value=\"Fix\" \/&gt;&lt;\/td&gt;\r\n\t\t\t\t\t\t\t\t\t\t&lt;td&gt;&lt;input type=\"button\" onclick=\"location.href = '\/jspexample\/updateIssue?id=&lt;c:out value=\"${item.id}\"\/&gt;&amp;newStatus=CLOSE'\" value=\"Close\" \/&gt;&lt;\/td&gt;\r\n\t\t\t\t\t\t\t\t\t\t&lt;td&gt;&lt;input type=\"button\" &lt;c:if test=\"${item.status == 'OPEN'}\"&gt; disabled=\"disabled\" &lt;\/c:if&gt; onclick=\"location.href = '\/jspexample\/updateIssue?id=&lt;c:out value=\"${item.id}\"\/&gt;&amp;newStatus=OPEN'\" value=\"Reopen\" \/&gt;&lt;\/td&gt;\r\n\t\t\t\t\t\t\t\t\t&lt;\/tr&gt;\r\n\t\t\t\t\t\t\t\t&lt;\/c:if&gt;\r\n\t\t\t\t\t\t\t&lt;\/c:forEach&gt;\r\n\t\t\t\t\t\t&lt;\/tbody&gt;\r\n\t\t\t\t\t&lt;\/table&gt;\t\t\t\t\r\n\t\t\t\t&lt;\/div&gt;\r\n\t\t\t&lt;\/div&gt;\r\n\t\t&lt;\/div&gt;\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t&lt;%\r\n\t\t\t}\r\n\t\t%&gt;\r\n\t&lt;\/div&gt;\t\r\n<\/pre>\n<p>First of all, the issue records are retrieved from the database through the <code>DbOperations<\/code> instance. In the JSP page, we can access to the other Java classes in the classpath. Please note that we already import the <code>DbOperations<\/code> class with JSP page directive at the top of the page. A compilation error occurs in the JSP page, unless you import an external Java class name.<\/p>\n<pre class=\"brush:java;\">\r\n&lt;%@ page import=\"com.javacodegeeks.examples.jspexample.db.DbOperations\"%&gt;\r\n...\r\n\t%\r\n\t\tList&lt; Issue &gt; issueList = DbOperations.getTheInstance().getAllIssues();\t\r\n<\/pre>\n<p>Notice the &#8220;if statement&#8221; before the issue list code. We will show the list, if only the issue list has at least one item. The html codes between the false condition statements are not rendered, because they are not added to the Jsp counterpart Servlet class by the compiler.    <\/p>\n<pre class=\"brush:java;\">\r\n        &lt;%\r\n\t     if ( issueList.size() &gt; 0 ) {\r\n\t%&gt;\r\n             .... \/\/ Issue list HTML codes.  \r\n        &lt;%\r\n            }\r\n        %&gt;\r\n<\/pre>\n<p>We use JSTL tag library in the JSP page. <code>&lt;c:forEach<\/code> tag creates the loop and for each item in the &#8220;issue list&#8221;, a table row is printed. In the loop, the issues with &#8216;CLOSE&#8217; status are not displayed in the list. We construct the &#8220;if statement&#8221; with the <code>&lt;c:if<\/code> JSTL tag. As you see, the condition is tested with <code>${item.status ne 'CLOSE'}<\/code>. This code is an example of <b>JSP expression language<\/b>. <b><code>ne<\/code><\/b> is represented as &#8216;not equal&#8217; and it is one of the JSP EL relational operators. The others are == (eq), != (ne),  (gt), = (ge).  <\/p>\n<pre class=\"brush:java;\">\r\n&lt;c:forEach items=\"${issueList}\" var=\"item\"&gt;\r\n    &lt;c:if test=\"${item.status ne 'CLOSE'}\"&gt;\r\n<\/pre>\n<p>How can we set different background colors to the issue rows depending on their status? We store the color codes in a &#8220;Map&#8221; of which the keys are their status data:<\/p>\n<pre class=\"brush:java;\">\r\n    Map issueColors = new HashMap();\r\n    issueColors.put( \"OPEN\", \"#E2C8C8\" );\r\n    issueColors.put( \"FIX\", \"#C1E212\" );\r\n <\/pre>\n<p>we access this map with an expression language pattern while determining the background color of the issue row:<\/p>\n<pre class=\"brush:java;\">\r\n     &lt;tr style=\"background-color: ${issueColors[item.status]}\"&gt;\r\n<\/pre>\n<p>We use the JSTL fmt (format) tag in order to format the issue &#8220;createDate&#8221; date variable: <\/p>\n<pre class=\"brush:java;\">\r\n    &lt;td&gt;&lt;fmt:formatDate value=\"${item.createDate}\" pattern=\"dd-MM-yyyy HH:mm\" \/&gt;&lt;\/td&gt;\r\n<\/pre>\n<p>We do not want the &#8220;fix button&#8221; being active if the issue status is already &#8216;FIX&#8217; and in a same manner, the &#8220;reopen button&#8221; should be active if the issue status is not &#8216;OPEN&#8217;. We provide it inserting JSTL &#8220;if statement&#8221; in the button HTML code and put <code>disabled=\"disabled\"<\/code> code if the relevant condition is true:<\/p>\n<pre class=\"brush:java;\">\r\n&lt;td&gt;&lt;input type=\"button\" &lt;c:if test=\"${item.status == 'FIX'}\"&gt; disabled=\"disabled\" &lt;\/c:if&gt; ...\r\n<\/pre>\n<p>In the example project, there is a simple &#8220;Java bean&#8221; class like below:<\/p>\n<pre class=\"brush:java;\">\r\npackage com.javacodegeeks.examples.jspexample.db.entity;\r\n\r\npublic class Company {\r\n\r\n\tprivate String\tname;\r\n\tprivate String\testablishYear;\r\n\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\r\n\tpublic void setName( final String name ) {\r\n\t\tthis.name = name;\r\n\t}\r\n\r\n\tpublic String getEstablishYear() {\r\n\t\treturn establishYear;\r\n\t}\r\n\r\n\tpublic void setEstablishYear( final String establishYear ) {\r\n\t\tthis.establishYear = establishYear;\r\n\t}\r\n}\r\n<\/pre>\n<p>To give an example of <b>Jsp actions<\/b>, we write a string &#8220;A company since 1998&#8221; in the page. &#8220;A&#8221; refers to the &#8220;name&#8221; variable and &#8220;1998&#8221; refers to the &#8220;establishYear&#8221; variable of the &#8220;Company&#8221; java bean. <b>useBean<\/b> jsp action uses the current java bean instance or creates new one if it does not exist. <b>setProperty<\/b> jsp action enables to set value to the property of the bean. <b>getProperty<\/b> jsp action inserts the property of a JavaBean into the output. In the example code, we print the values of the &#8220;Company&#8221; bean properties ( name and establishYear ) after setting values ( &#8220;A&#8221;, &#8220;1998&#8221; ) to them:<\/p>\n<pre class=\"brush:java;\">  \r\n\t&lt;div&gt;\r\n\t\t&lt;jsp:useBean id=\"companyBean\" class=\"com.javacodegeeks.examples.jspexample.db.entity.Company\" \/&gt;\r\n\t\t\r\n\t\t&lt;jsp:setProperty property=\"name\" name=\"companyBean\" value=\"A\"\/&gt;\r\n\t\t&lt;jsp:setProperty property=\"establishYear\" name=\"companyBean\" value=\"1998\"\/&gt;\r\n\t\t\r\n\t\t&lt;b&gt;&lt;jsp:getProperty property=\"name\" name=\"companyBean\"\/&gt;&lt;\/b&gt; company since \r\n\t\t&lt;b&gt;&lt;jsp:getProperty property=\"establishYear\" name=\"companyBean\"\/&gt;&lt;\/b&gt;\r\n\t&lt;\/div&gt;\r\n<\/pre>\n<p>Now I would like to mention the Servlets in the example. When we click on the &#8220;submit&#8221; button in the form, the &#8220;doPost&#8221; method of the &#8220;AddIssueServlet&#8221; servlet evaluates this action. The parameter values are transported via the request object. In this &#8220;doPost&#8221; method, these parameter values are taken and used to insert a new issue record in the database. Then the servlet invokes the jsp page to render again with the Servlet <code>sendRedirect<\/code> method. The name of the our JSP page is &#8220;index.jsp&#8221;. Please note that &#8220;index.jsp&#8221; page is the default welcome page, so you do not have to write it explicitly. Thus we only set &#8220;\/jspexample\/&#8221; ( context root name of the application ) as the parameter of the &#8220;sendRedirect&#8221; method call:<\/p>\n<pre class=\"brush:java;\">\r\npackage com.javacodegeeks.examples.jspexample.servlet;\r\n\r\nimport java.io.IOException;\r\n\r\nimport javax.servlet.ServletException;\r\nimport javax.servlet.annotation.WebServlet;\r\nimport javax.servlet.http.HttpServlet;\r\nimport javax.servlet.http.HttpServletRequest;\r\nimport javax.servlet.http.HttpServletResponse;\r\n\r\nimport com.javacodegeeks.examples.jspexample.db.DbOperations;\r\n\r\n@WebServlet( value = \"\/addIssue\" )\r\npublic class AddIssueServlet extends HttpServlet {\r\n\r\n\tprivate static final long\tserialVersionUID\t= -1L;\r\n\r\n\t@Override\r\n\tprotected void doPost( final HttpServletRequest request, final HttpServletResponse response )\r\n\t\tthrows ServletException, IOException {\r\n\r\n\t\tfinal String title = request.getParameter( \"title\" );\r\n\t\tfinal String openedBy = request.getParameter( \"openedby\" );\r\n\t\tfinal String priority = request.getParameter( \"priority\" );\r\n\t\tfinal String comments = request.getParameter( \"comments\" );\r\n\r\n\t\tDbOperations.getTheInstance().addNewIssueRecord( title, openedBy, priority, comments );\r\n\r\n\t\tresponse.sendRedirect( \"\/jspexample\/\" );\r\n\t}\r\n}\r\n<\/pre>\n<p>Clicking the &#8220;fix&#8221;, &#8220;close&#8221; and &#8220;reopen&#8221; buttons in the issue list rows fires another Servlet event in order to update the status of the current issue:<\/p>\n<pre class=\"brush:java;\">\r\npackage com.javacodegeeks.examples.jspexample.servlet;\r\n\r\nimport java.io.IOException;\r\n\r\nimport javax.servlet.ServletException;\r\nimport javax.servlet.annotation.WebServlet;\r\nimport javax.servlet.http.HttpServlet;\r\nimport javax.servlet.http.HttpServletRequest;\r\nimport javax.servlet.http.HttpServletResponse;\r\n\r\nimport com.javacodegeeks.examples.jspexample.db.DbOperations;\r\n\r\n@WebServlet( value = \"\/updateIssue\" )\r\npublic class UpdateIssueServlet extends HttpServlet {\r\n\r\n\tprivate static final long\tserialVersionUID\t= -1L;\r\n\r\n\t@Override\r\n\tprotected void doGet( final HttpServletRequest request, final HttpServletResponse response )\r\n\t\tthrows ServletException, IOException {\r\n\r\n\t\tfinal String newStatus = request.getParameter( \"newStatus\" );\r\n\t\tfinal String id = request.getParameter( \"id\" );\r\n\r\n\t\tDbOperations.getTheInstance().updateIssueRecord( id, newStatus );\r\n\r\n\t\tresponse.sendRedirect( \"\/jspexample\/\" );\r\n\t}\r\n}\r\n<\/pre>\n<h2>4. Download the Eclipse Project<\/h2>\n<p>This code demonstrates JSP basics in a simple example. Download link is below.<\/p>\n<div class=\"download\">\n<strong>Download<\/strong><br \/>You can download the full source code of this example here : <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/06\/jspexample.zip\"><strong>jspexample<\/strong><\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>JSP is a server side technology which helps to create dynamic, platform-independent java web applications and is mainly used for implementing the presentation layer. In this tutorial, we will look into the essentials of the JSP technology with illustrating some simple code. As a prerequisite of this post, we assume you have knowledge what is &hellip;<\/p>\n","protected":false},"author":48,"featured_media":1240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-23870","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jsp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JSP Tutorial For Beginners - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"JSP is a server side technology which helps to create dynamic, platform-independent java web applications and is mainly used for implementing the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JSP Tutorial For Beginners - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"JSP is a server side technology which helps to create dynamic, platform-independent java web applications and is mainly used for implementing the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/ilker.konar.7\" \/>\n<meta property=\"article:published_time\" content=\"2015-06-09T08:00:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-08-02T14:26:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ilker Konar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ilker Konar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"22 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/\"},\"author\":{\"name\":\"Ilker Konar\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6e006fb417fee303fa4ad4b29644a116\"},\"headline\":\"JSP Tutorial For Beginners\",\"datePublished\":\"2015-06-09T08:00:29+00:00\",\"dateModified\":\"2015-08-02T14:26:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/\"},\"wordCount\":2621,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"articleSection\":[\"jsp\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/\",\"name\":\"JSP Tutorial For Beginners - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"datePublished\":\"2015-06-09T08:00:29+00:00\",\"dateModified\":\"2015-08-02T14:26:03+00:00\",\"description\":\"JSP is a server side technology which helps to create dynamic, platform-independent java web applications and is mainly used for implementing the\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"jsp\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/jsp\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JSP Tutorial For Beginners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6e006fb417fee303fa4ad4b29644a116\",\"name\":\"Ilker Konar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Ilker-Konar-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Ilker-Konar-96x96.jpg\",\"caption\":\"Ilker Konar\"},\"description\":\"I am a senior software developer with experience mostly in java-related technologies with appliance in the telecommunication industry. I have been programming for more than fifteen years. I am passionate about programming. I like learning new frameworks, languages and design patterns.\",\"sameAs\":[\"http:\/\/examples.javacodegeeks.com\/author\/ilker-konar\/\",\"http:\/\/www.facebook.com\/ilker.konar.7\",\"https:\/\/www.linkedin.com\/in\/ilkerkonar\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/ilker-konar\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JSP Tutorial For Beginners - Java Code Geeks","description":"JSP is a server side technology which helps to create dynamic, platform-independent java web applications and is mainly used for implementing the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/","og_locale":"en_US","og_type":"article","og_title":"JSP Tutorial For Beginners - Java Code Geeks","og_description":"JSP is a server side technology which helps to create dynamic, platform-independent java web applications and is mainly used for implementing the","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"http:\/\/www.facebook.com\/ilker.konar.7","article_published_time":"2015-06-09T08:00:29+00:00","article_modified_time":"2015-08-02T14:26:03+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Ilker Konar","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Ilker Konar","Est. reading time":"22 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/"},"author":{"name":"Ilker Konar","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6e006fb417fee303fa4ad4b29644a116"},"headline":"JSP Tutorial For Beginners","datePublished":"2015-06-09T08:00:29+00:00","dateModified":"2015-08-02T14:26:03+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/"},"wordCount":2621,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","articleSection":["jsp"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/","name":"JSP Tutorial For Beginners - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","datePublished":"2015-06-09T08:00:29+00:00","dateModified":"2015-08-02T14:26:03+00:00","description":"JSP is a server side technology which helps to create dynamic, platform-independent java web applications and is mainly used for implementing the","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-tutorial-beginners\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"jsp","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/jsp\/"},{"@type":"ListItem","position":5,"name":"JSP Tutorial For Beginners"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6e006fb417fee303fa4ad4b29644a116","name":"Ilker Konar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Ilker-Konar-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Ilker-Konar-96x96.jpg","caption":"Ilker Konar"},"description":"I am a senior software developer with experience mostly in java-related technologies with appliance in the telecommunication industry. I have been programming for more than fifteen years. I am passionate about programming. I like learning new frameworks, languages and design patterns.","sameAs":["http:\/\/examples.javacodegeeks.com\/author\/ilker-konar\/","http:\/\/www.facebook.com\/ilker.konar.7","https:\/\/www.linkedin.com\/in\/ilkerkonar"],"url":"https:\/\/examples.javacodegeeks.com\/author\/ilker-konar\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/23870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=23870"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/23870\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1240"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=23870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=23870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=23870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}