{"id":24741,"date":"2015-07-09T15:00:20","date_gmt":"2015-07-09T12:00:20","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=24741"},"modified":"2015-08-02T17:27:33","modified_gmt":"2015-08-02T14:27:33","slug":"jsp-scriptlet-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/","title":{"rendered":"Jsp Scriptlet Example"},"content":{"rendered":"<p>JSP technology enables you to add dynamic content to web pages with scripting elements. In a JSP page, a <b>Scriptlet<\/b> is a block of Java code enclosed by the pair &lt;% and %&gt;. In this post, we will demonstrate how to use scriptlets in a web application example.<\/p>\n<p>Every Java executable statements &#8211; <i>variable declarations, manipulating Java objects, invoking the methods, catching Java exceptions&#8230;<\/i> can be embedded in a JSP Scriptlet. For example, the code includes two scriptlets that let you display an HTML element or not depending on a condition:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;% if (condition) { %&gt;\r\n   <p>This is only shown if the condition is true<\/p>\r\n&lt;% } %&gt;\r\n<\/pre>\n<p>In the scriptlet elements, you can do more. For example, you can connect to a database, read a file, and get the data. Then you can handle this data, make some calculations and decide to show some certain HTML elements or how to show them. In this way, web pages gain high flexibility.<\/p>\n<h2>1. Overview<\/h2>\n<p>In the example, we create a &#8216;Pizza Order&#8217; form in a JSP page with the help of scriptlets. This form takes action to forward to the other JSP page that displays the order details. Our preferred IDE is Eclipse. We use \u2018Maven\u2019 for the dependency management. We create a dynamic web application and deploy it into the Tomcat server. In one of my previous examples, I have explained how to create a Maven dynamic web application in the Eclipse, how to define a \u201cTomcat\u201d server and add the application to it. You can examine: <a href=\"http:\/\/examples.javacodegeeks.com\/enterprise-java\/logback\/logback-mapped-diagnostic-contexts-mdc-example\/\" target=\"_blank\">Logback Mapped Diagnostic Contexts (MDC) Example<\/a><\/p>\n<h2>2. JSP Code<\/h2>\n<p>You see the form in the Browser. The user can pick the pizza type and its size with single-selection radio buttons. If she would like to, she can add some extra toppings to the pizza using multiple-choice checkboxes. Also, the user is informed about the prices.<\/p>\n<p><figure id=\"attachment_24788\" aria-describedby=\"caption-attachment-24788\" style=\"width: 576px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample1.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample1.jpg\" alt=\"Pizza Order Form\" width=\"576\" height=\"572\" class=\"size-full wp-image-24788\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample1.jpg 576w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample1-150x150.jpg 150w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample1-300x298.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample1-70x70.jpg 70w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><\/a><figcaption id=\"caption-attachment-24788\" class=\"wp-caption-text\">Pizza Order Form<\/figcaption><\/figure><\/p>\n<p>At the top of the JSP page, we add some scriptlet codes that define the data structures which keep the data in the JSP page. We create lists for pizza types and pizza toppings and add some data to them. Alternatively, you can read the data from database or files, then use and manipulate them in your JSP scriptlets. We put the lists in the Session Object after we initially create them. In the following requests, we get the list instances from the Session Object:<\/p>\n<pre class=\"brush:java\">\r\n&lt;%@ page language=\"java\" contentType=\"text\/html; charset=ISO-8859-1\" pageEncoding=\"ISO-8859-1\"%&gt;\r\n&lt;%@ page import=\"com.javacodegeeks.examples.jspscriptletexample.Pizza\" %&gt;\r\n&lt;%@ page import=\"java.util.*\"%&gt;\r\n\r\n&lt;% \r\n\tObject sessionObj = request.getSession().getAttribute( \"pizzaTypeList\" );\r\n\r\n\tList pizzaTypes = null;\r\n\t\r\n\tif ( sessionObj == null ) {\r\n\t\t\r\n\t\tpizzaTypes = new ArrayList();\r\n\t\t\r\n\t\tpizzaTypes.add( new Pizza( \"Kebab\", 15.23f ) );\r\n\t\tpizzaTypes.add( new Pizza( \"Vegetarian\", 11.48f ) );\r\n\t\tpizzaTypes.add( new Pizza( \"Meat Feast\", 14.05f ) );\r\n\t\tpizzaTypes.add( new Pizza( \"Sea Food\", 17.82f ) );\r\n\t\t\r\n\t\trequest.getSession().setAttribute( \"pizzaTypeList\", pizzaTypes );\r\n\t\t\r\n\t} else {\t\t\r\n\t\tpizzaTypes = ( List ) sessionObj;\r\n\t}\r\n\t\r\n\tsessionObj = request.getSession().getAttribute( \"pizzaToppingsList\" );\r\n\t\r\n\tList pizzaToppings = null;\r\n\t\r\n\tif ( sessionObj == null ) {\r\n\t\t\r\n\t\tpizzaToppings = new ArrayList();\r\n\t\t\r\n\t\tpizzaToppings.add( \"Tomatoes\" );\r\n\t\tpizzaToppings.add( \"Green Onion\" );\r\n\t\tpizzaToppings.add( \"Broccoli\" );\r\n\t\tpizzaToppings.add( \"Green Peppers\" );\r\n\t\tpizzaToppings.add( \"Red Peppers\" );\r\n\t\tpizzaToppings.add( \"Mushroom\" );\r\n\t\tpizzaToppings.add( \"Ham\" );\r\n\t\tpizzaToppings.add( \"Chicken\" );\r\n\t\tpizzaToppings.add( \"Beef\" );\r\n\t\tpizzaToppings.add( \"Pepperoni\" );\r\n\t\tpizzaToppings.add( \"Salami\" );\r\n\t\tpizzaToppings.add( \"Parmesan Cheese\" );\r\n\t\tpizzaToppings.add( \"Mozzarella\" );\r\n\t\tpizzaToppings.add( \"Cheese\" );\r\n\t\t\r\n\t\trequest.getSession().setAttribute( \"pizzaToppingsList\", pizzaToppings );\r\n\t\t\r\n\t} else {\r\n\t\tpizzaToppings = ( List ) sessionObj;\r\n\t}\r\n   ...\r\n<\/pre>\n<p><b>Pizza<\/b> is the model bean class that keeps the pizza attributes:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>Pizza.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">\r\npublic class Pizza implements Serializable {\r\n\r\n\tprivate static final long\tserialVersionUID\t= -8549196728165055605L;\r\n\r\n\tprivate final String\t\tname;\r\n\r\n\tprivate final float\t\t\tprice;\r\n\r\n\tpublic Pizza( final String name, final float price ) {\r\n\t\tthis.name = name;\r\n\t\tthis.price = price;\r\n\t}\r\n\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\r\n\tpublic float getPrice() {\r\n\t\treturn price;\r\n\t}\r\n}\r\n<\/pre>\n<p>The form section of the JSP page is shown below. In the lines of 09-15, the list items are produced in a for loop traversed in the pizza type list. With JSP scriptlet, you do not have to write all of the list items statically. If you retrieve the data to be shown, you can manipulate it in order to create and display HTML tags in a JSP page. Between the lines 30 &#8211; 56, you see the pizza extra toppings section in which the topping items are displayed with 3 columns grid form. In each column, there is a separate HTML list. At the top of the form, the size of each HTML list is calculated with division of the toppings list length by 3 and the result is stored in the <b>sliceSize<\/b> variable. We also keep the remainder of this division calculation in order to use below. <\/p>\n<p>In this extra toppings section, we use two nested for loops: The outer one is for each column, the inner one is for the list items in its column. We divide the extra toppings List by there. The first part of the list is shown in the first column, the second part in the second column and the last part in the last column. If there is any remainder items after the division, we append them to the first and second lists. We design the allotment of the extra toppings items to the 3 column grid with this logic. Of course, different algorithms can be planned. <\/p>\n<pre class=\"brush:java;wrap-lines:false\">\r\n...\r\n&lt;%\r\n   int sliceSize = pizzaToppings.size() \/ 3;\r\n   int remainder = pizzaToppings.size() % 3;\r\n%&gt;\r\n&lt;form action=\"orderResult.jsp\" method=\"POST\"&gt;\r\n\t&lt;h3&gt;Pizza Types&lt;\/h3&gt;\r\n\t&lt;div&gt;\r\n\t\t&lt;ul&gt;\r\n\t\t\t&lt;% for ( Pizza pizza : pizzaTypes ) { %&gt;\r\n\t\t\t&lt;li&gt;\r\n\t\t\t\t&lt;input type=\"radio\" name=\"pizzaTypeOptions\" value=\"&lt;%=pizza.getName()%&gt;\" checked \/&gt;\r\n\t\t\t\t&lt;span class=\"pizzaType\"&gt;&lt;%=pizza.getName()%&gt;&lt;\/span&gt;\r\n\t\t\t\t&lt;span class=\"pizzaPrice\"&gt;&lt;%=pizza.getPrice()%&gt;$&lt;\/span&gt;\r\n\t\t\t&lt;\/li&gt;\r\n\t\t\t&lt;% } %&gt;\r\n\t\t&lt;\/ul&gt;\r\n\t&lt;\/div&gt;\r\n\t&lt;h3&gt;Size&lt;\/h3&gt;\r\n\t&lt;ul&gt;\r\n\t\t&lt;li id=\"li_1\"&gt;\r\n\t\t\t&lt;input id=\"pizza_size1\" type=\"radio\" name=\"pizzaSizeOptions\" value=\"Small\" checked\/&gt;\r\n\t\t\t&lt;span class=\"pizzaSize\"&gt;Small&lt;\/span&gt;\r\n\t\t\t&lt;input id=\"pizza_size2\" type=\"radio\" name=\"pizzaSizeOptions\" value=\"Medium\"\/&gt;\r\n\t\t\t&lt;span class=\"pizzaSize\"&gt;Medium ( + 2$ )&lt;\/span&gt;\r\n\t\t\t&lt;input id=\"pizza_size3\" type=\"radio\" name=\"pizzaSizeOptions\" value=\"Large\"\/&gt;\r\n\t\t\t&lt;span class=\"pizzaSize\"&gt;Large ( + 3$ )&lt;\/span&gt;\r\n\t\t&lt;\/li&gt;\r\n\t&lt;\/ul&gt;\r\n\t&lt;h3&gt;Extra Toppings&lt;\/h3&gt;\r\n\t&lt;div class=\"section group\"&gt;\r\n\t\t&lt;% for ( int j = 0; j &lt; 3; j++ ) { %&gt;\r\n\t\t&lt;div class=\"col span_1_of_3\"&gt;\r\n\t\t\t&lt;ul class=\"ul_2\"&gt;\r\n\t\t\t\t&lt;% for ( int i = sliceSize * j; i &lt; ( j + 1 ) * sliceSize; i++ ) { %&gt;\r\n\t\t\t\t&lt;li class=\"li_2\"&gt;\t\t\t\t\t\t\r\n\t\t\t\t\t&lt;input type=\"checkbox\" name=\"pizzaToppings\" value=\"&lt;%=pizzaToppings.get( i )%&gt;\"\/&gt;\r\n\t\t\t\t\t&lt;%=pizzaToppings.get( i )%&gt;\r\n\t\t\t\t&lt;\/li&gt;\r\n\t\t\t\t&lt;% } \r\n\t\t\t\t\t\r\n\t\t\t\tif ( j == 0 &amp;&amp; remainder &gt; 0 ) {\r\n\t\t\t\t%&gt;\t\r\n\t\t\t\t&lt;li class=\"li_2\"&gt;\t\t\t\t\t\t\r\n\t\t\t\t\t&lt;input type=\"checkbox\" name=\"pizzaToppings\" value=\"&lt;%=pizzaToppings.get( pizzaToppings.size() - 2 )%&gt;\"\/&gt;\r\n\t\t\t\t\t&lt;%=pizzaToppings.get( pizzaToppings.size() - 2 )%&gt;\r\n\t\t\t\t&lt;\/li&gt;\t\t\t\t\t\t\r\n\t\t\t\t&lt;% } else if ( j == 1 &amp;&amp; remainder &gt; 1 ) { %&gt;\r\n\t\t\t\t&lt;li class=\"li_2\"&gt;\t\t\t\t\t\t\r\n\t\t\t\t\t&lt;input type=\"checkbox\" name=\"pizzaToppings\" value=\"&lt;%=pizzaToppings.get( pizzaToppings.size() - 1 )%&gt;\"\/&gt;\r\n\t\t\t\t\t&lt;%=pizzaToppings.get( pizzaToppings.size() - 1 )%&gt;\r\n\t\t\t\t&lt;\/li&gt;\t\t\t\t\t\t\r\n\t\t\t\t&lt;% } %&gt;\r\n\t\t\t&lt;\/ul&gt;\r\n\t\t&lt;\/div&gt;\r\n\t\t&lt;% } %&gt;\r\n\t&lt;\/div&gt;\t\r\n\t&lt;h4&gt;Each extra topping is 0.65$&lt;\/h4&gt;\t\r\n\t&lt;input type=\"submit\" value=\"Order\"\/&gt;\t\t\t\t\r\n&lt;\/form&gt;\r\n...\r\n<\/pre>\n<p>Please notice that this form is submitted to the other JSP page: <code>orderResult.jsp<\/code>. <\/p>\n<pre class=\"brush:java;\">\r\n   &lt;form action=\"orderResult.jsp\" method=\"POST\"&gt;\r\n<\/pre>\n<p>In this page, we summarize the items the user preferred in the previous form. Also we calculate the total amount and display the result:<\/p>\n<p><figure id=\"attachment_24858\" aria-describedby=\"caption-attachment-24858\" style=\"width: 541px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample2.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample2.jpg\" alt=\"Order Result Page\" width=\"541\" height=\"182\" class=\"size-full wp-image-24858\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample2.jpg 541w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample2-300x101.jpg 300w\" sizes=\"(max-width: 541px) 100vw, 541px\" \/><\/a><figcaption id=\"caption-attachment-24858\" class=\"wp-caption-text\">Order Result Page<\/figcaption><\/figure><\/p>\n<p><span style=\"text-decoration: underline\"><em>orderResult.jsp<\/em><\/span><\/p>\n<pre class=\"brush:java;wrap-lines:false;highlight:[32]\">\r\n&lt;%@ page language=\"java\" contentType=\"text\/html; charset=ISO-8859-1\" pageEncoding=\"ISO-8859-1\"%&gt;\r\n&lt;%@ page import=\"com.javacodegeeks.examples.jspscriptletexample.Pizza\" %&gt;\r\n&lt;%@ page import=\"java.util.*\"%&gt;\r\n\r\n&lt;%! \r\n\tpublic String prepareOutput( final String[] toppings, final String pizzaSize, \r\n\t\tfinal String pizzaType ) {\r\n\t\t\r\n\t\tString output = pizzaSize + \" '\" + pizzaType + \r\n\t\t\t\"' pizza with these extra toppings : \";\r\n\t\t\r\n\t\tfor ( int i = 0; i &lt; toppings.length; i++ ) {\r\n\t\t\toutput += toppings[ i ];\r\n\t\t\t\r\n\t\t\tif ( i != toppings.length - 1 ) {\r\n\t\t\t\toutput += \", \";\r\n\t\t\t}\r\n\t\t} \r\n\t\t\r\n\t\treturn output;\r\n\t}\t \r\n%&gt;\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n\t&lt;meta charset=\"UTF-8\"&gt;\r\n\t&lt;title&gt;Jsp Scriptlet Example&lt;\/title&gt;\r\n\t&lt;link rel=\"stylesheet\" href=\".\/static\/css\/pizzaorder.css\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\t&lt;h3&gt;Order Details&lt;\/h3&gt;\r\n\t&lt;p&gt;&lt;%=prepareOutput( request.getParameterValues( \"pizzaToppings\" ), request.getParameter( \"pizzaSizeOptions\" ), \r\n\t\trequest.getParameter( \"pizzaTypeOptions\" ) )%&gt;&lt;\/p&gt;\r\n\t&lt;p&gt;TOTAL:\r\n\t&lt;% \r\n\t\tList&lt;Pizza&gt; pizzaTypes = ( List&lt;Pizza&gt; ) request.getSession().getAttribute( \"pizzaTypeList\" );\r\n\t\t\r\n\t\tfloat price = 0f;\r\n\t\t\r\n\t\tfor ( Pizza pizza : pizzaTypes ) {\r\n\t\t\tif ( pizza.getName().equals( request.getParameter( \"pizzaTypeOptions\" ) ) ) {\r\n\t\t\t\tprice = pizza.getPrice();\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t\t\t\r\n\t\tString size = request.getParameter( \"pizzaSizeOptions\" );\r\n\t\t\r\n\t\tprice += size.equals( \"Medium\" ) ? 2f : ( size.equals( \"Large\" ) ? 3f : 0f );\r\n\t\t\r\n\t\tprice += request.getParameterValues( \"pizzaToppings\" ).length * 0.65f;\r\n\t\t\r\n\t\tout.print( price );\r\n\t%&gt;\r\n\t$ \r\n\t&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>We build the summary string in a method ( prepareOutput ) that we create it in the JSP declaration tag ( &lt;%! %&gt;) at the top of the JSP page. Then we invoke this method in line 32 with the request parameters that posted in the previous form. As you see, we can declare any method and invoke them in the JSP scriptlets.<\/p>\n<p>In the next scriptlet, we calculate the total price amount. First we get the pizza type that the user select from the related request parameter. We get its price in its bean class stored in the Session. We add 2 or 3 dollars if the user prefers medium or large size, respectively. Finally, we count the extra toppings selected, multiply it by the fixed item price ( 0.65 ) and add the result to the sum. Then we output the total. Please notice that we locate the scriptlet immediately before the dollar sign ( $ ). It can be at the beginning of the JSP and we can store the result in a variable. But we prefer to locate it in the place that is displayed. You are free in the location decision of the scriptlets. But you should also take into account the code readability.      <\/p>\n<h2>3. JSP Scriptlet Debugging<\/h2>\n<p>In the modern IDEs like Eclipse, you are able to debug the JSP scriptlet code. After starting the application server ( Tomcat, Weblogic, &#8230; ) in debug mode, you can toggle any breakpoint, watch the variables in the scriptlet code. You see the debugging session in the <code>orderSession.jsp<\/code> with the Eclipse.<\/p>\n<p><figure id=\"attachment_24868\" aria-describedby=\"caption-attachment-24868\" style=\"width: 776px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample3.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample3.jpg\" alt=\"Debugging JSP Scriptlet\" width=\"776\" height=\"258\" class=\"size-full wp-image-24868\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample3.jpg 776w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample3-300x100.jpg 300w\" sizes=\"(max-width: 776px) 100vw, 776px\" \/><\/a><figcaption id=\"caption-attachment-24868\" class=\"wp-caption-text\">Debugging JSP Scriptlet<\/figcaption><\/figure><\/p>\n<p>Here is the variables section of the Eclipse Debug Perspective. You can watch variables values while debugging:<\/p>\n<p><figure id=\"attachment_24870\" aria-describedby=\"caption-attachment-24870\" style=\"width: 734px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample4.jpg\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample4.jpg\" alt=\"Debugging JSP Scriptlet\" width=\"734\" height=\"229\" class=\"size-full wp-image-24870\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample4.jpg 734w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/jspScriptletExample4-300x94.jpg 300w\" sizes=\"(max-width: 734px) 100vw, 734px\" \/><\/a><figcaption id=\"caption-attachment-24870\" class=\"wp-caption-text\">Debugging JSP Scriptlet<\/figcaption><\/figure><\/p>\n<h2>4. Download the Eclipse Project<\/h2>\n<p>This code demonstrates JSP scriptlets in a simple web application. Download link is below.<\/p>\n<div class=\"download\"><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\/07\/jspScriptletExample.zip\"><strong>jspScriptletExample<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>JSP technology enables you to add dynamic content to web pages with scripting elements. In a JSP page, a Scriptlet is a block of Java code enclosed by the pair &lt;% and %&gt;. In this post, we will demonstrate how to use scriptlets in a web application example. Every Java executable statements &#8211; variable declarations, &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":[981],"class_list":["post-24741","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jsp","tag-scriplet"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Jsp Scriptlet Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"JSP technology enables you to add dynamic content to web pages with scripting elements. In a JSP page, a Scriptlet is a block of Java code enclosed by 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-scriptlet-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Jsp Scriptlet Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"JSP technology enables you to add dynamic content to web pages with scripting elements. In a JSP page, a Scriptlet is a block of Java code enclosed by the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/\" \/>\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-07-09T12:00:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-08-02T14:27:33+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=\"9 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-scriptlet-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/\"},\"author\":{\"name\":\"Ilker Konar\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6e006fb417fee303fa4ad4b29644a116\"},\"headline\":\"Jsp Scriptlet Example\",\"datePublished\":\"2015-07-09T12:00:20+00:00\",\"dateModified\":\"2015-08-02T14:27:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/\"},\"wordCount\":1017,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"keywords\":[\"scriplet\"],\"articleSection\":[\"jsp\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/\",\"name\":\"Jsp Scriptlet Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"datePublished\":\"2015-07-09T12:00:20+00:00\",\"dateModified\":\"2015-08-02T14:27:33+00:00\",\"description\":\"JSP technology enables you to add dynamic content to web pages with scripting elements. In a JSP page, a Scriptlet is a block of Java code enclosed by the\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#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-scriptlet-example\/#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 Scriptlet Example\"}]},{\"@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 Scriptlet Example - Java Code Geeks","description":"JSP technology enables you to add dynamic content to web pages with scripting elements. In a JSP page, a Scriptlet is a block of Java code enclosed by 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-scriptlet-example\/","og_locale":"en_US","og_type":"article","og_title":"Jsp Scriptlet Example - Java Code Geeks","og_description":"JSP technology enables you to add dynamic content to web pages with scripting elements. In a JSP page, a Scriptlet is a block of Java code enclosed by the","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/","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-07-09T12:00:20+00:00","article_modified_time":"2015-08-02T14:27:33+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":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/"},"author":{"name":"Ilker Konar","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/6e006fb417fee303fa4ad4b29644a116"},"headline":"Jsp Scriptlet Example","datePublished":"2015-07-09T12:00:20+00:00","dateModified":"2015-08-02T14:27:33+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/"},"wordCount":1017,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","keywords":["scriplet"],"articleSection":["jsp"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/","name":"Jsp Scriptlet Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","datePublished":"2015-07-09T12:00:20+00:00","dateModified":"2015-08-02T14:27:33+00:00","description":"JSP technology enables you to add dynamic content to web pages with scripting elements. In a JSP page, a Scriptlet is a block of Java code enclosed by the","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jsp\/jsp-scriptlet-example\/#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-scriptlet-example\/#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 Scriptlet Example"}]},{"@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\/24741","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=24741"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/24741\/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=24741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=24741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=24741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}