{"id":149,"date":"2016-01-25T21:10:15","date_gmt":"2016-01-25T21:10:15","guid":{"rendered":"http:\/\/kaizen-koka.com\/?p=149"},"modified":"2017-07-18T03:56:46","modified_gmt":"2017-07-18T03:56:46","slug":"jsp-java-server-pages","status":"publish","type":"post","link":"https:\/\/kaizen-koka.com\/?p=149","title":{"rendered":"JSP (java server pages)"},"content":{"rendered":"<p>\n\t<strong><span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">JSP will be divided <\/span><\/span><\/strong><span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>in to<\/strong><\/span><\/span><strong><span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"> 3 sections<\/span><\/span><\/strong>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">Scriplets<br \/>\n\tExpressions<br \/>\n\tDeclarations<\/span><\/span>\n<\/p>\n<p>\n\t<br \/>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>Life Cycle Of JSP:<\/strong><br \/>\n\tTranslated servlet of a jsp contains the following&nbsp;<br \/>\n\tjspInit()<br \/>\n\t_jspService()<br \/>\n\tjspDestroy()<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">scriplet:&nbsp;<br \/>\n\t&nbsp;.is a jsp element in which we can write any java valid stmt.<br \/>\n\t&nbsp;.All the java stmts inside the scriptlet must be terminated with the semi colon<br \/>\n\t&nbsp;.Write the scriplet &lt;% %&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>Expressions:&nbsp;<\/strong><br \/>\n\t&nbsp;.Is a jsp element which is shortcut form of out.println.<br \/>\n\t&nbsp;.&lt;%= &quot;i am an exp&quot;%&gt;<br \/>\n\t&nbsp;.Semicolon is not allowed in the expression<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>Declaration:<\/strong><br \/>\n\t&nbsp;.Is a jsp element in which we can write the following<br \/>\n\t&nbsp;1) variable declarations<br \/>\n\t&nbsp;2) method definations<br \/>\n\t&nbsp;3) class definations<br \/>\n\t&nbsp;4) inteface definations<br \/>\n\t&nbsp;Syntax : &lt;%! %&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;<strong>Directives: <\/strong>is an instruction given to the container for a particular task.<br \/>\n\t&nbsp;1) include&nbsp;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;is used to include another jsp or html<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%@include file =&quot;filename&quot;%&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;When we use include directive the directive statement will be replaced with contents of include jsp or html<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;2) page<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;must be the first line the jsp<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%@ page extends= &quot;&quot; %&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%@ page contentType=&quot;text\/xml&quot; %&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%@ page errorPage=&quot;MyErrorPage.jsp&quot; %&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%@ page isErrorPage=&quot;true&quot; %&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%@ page import=&quot;java.sql.*&quot; %&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;%@ page session=&quot;true&quot; %&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;3) taglib directive is used to use the sun taglibraries(JSTL java standard tag libraries) and your own custom taglibraries<\/span><\/span>\n<\/p>\n<p>\n\t<br \/>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>&nbsp;JSP Standard Action:<\/strong><br \/>\n\t&nbsp;&nbsp;&lt;jsp:include&gt;<br \/>\n\t&nbsp;&nbsp;&lt;jsp:forward&gt;<br \/>\n\t&nbsp;&nbsp;&lt;jsp:param&gt;<br \/>\n\t&nbsp;&nbsp;&lt;jsp:useBean&gt;<br \/>\n\t&nbsp;&nbsp;&lt;jsp:setProperty&gt;<br \/>\n\t&nbsp;&nbsp;&lt;jsp:getProperty&gt;<br \/>\n\t&nbsp;&nbsp;&lt;jsp:plugin&gt;<br \/>\n\t&nbsp;&nbsp;&lt;jsp:fallback&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">Include : This action is used to include another jsp or html<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:include page=&quot;html or jsp file&quot;\/&gt;<br \/>\n\tForward : Used to forward a request from current jsp to another jsp or html<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&lt;jsp:forward page=&quot;any file&quot;\/&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;&nbsp;&nbsp;.Include and Forward actions functionality similar to request dispatcher interface include() and forward()methods<br \/>\n\t&nbsp;&nbsp;&nbsp;.When use include, control will be transfered to include.jsp and executes and excuted response will be included and continue the execution of statement next to include action.<br \/>\n\t&nbsp;&nbsp;&nbsp;.When we use forward, control will be forwarded to the specified jsp. Its won&#39;t execute statements after forward<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;Param: Used along with &lt;jsp:include&gt; and &lt;jsp:forward&gt; . Used to send the parameters form current jsp to another jsp that included or forwarded.<br \/>\n\t&nbsp;&nbsp;&nbsp;&lt;jsp:param name=&quot;name&quot; value=&quot;siva&quot;\/&gt;<br \/>\n\tUseBean :<br \/>\n\t&nbsp;&nbsp;&lt;%@ page import=&quot;com.bellinfo.Student&quot; %&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&lt;jsp:useBean id=&quot;ss&quot; class=&quot;Student&quot; scope=&quot;request&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&lt;jsp:setProperty name=&quot;ss&quot; property=&quot;id&quot; value=&quot;99&quot;\/&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp;&lt;jsp:setProperty name=&quot;ss&quot; property=&quot;name&quot; value=&quot;siva&quot;\/&gt;<br \/>\n\t&nbsp;&nbsp;&lt;jsp:forward page=&quot;xyz.jsp&quot;\/&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;&nbsp;&lt;jsp:getProperty name=&quot;ss&quot; property=&quot;id&quot;\/&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;<strong>&nbsp;JSP Scopes:<\/strong><br \/>\n\t&nbsp;&nbsp;1) Page &nbsp;&#8211; Any obeject with in the page scope can be accessible with in a jsp&nbsp;<br \/>\n\t&nbsp;&nbsp;2) Request &#8211; Any object with in request scope can be accessible across multiple jsps with in one req and res mechnaism<br \/>\n\t&nbsp;&nbsp;3) Session &#8211; Any obejct with session scope can be accessible across multiple jsps and multiple request from one client<br \/>\n\t&nbsp;&nbsp;4) Application &#8211; Any obejct with application scope can be accessed across multiple pages, multiple request and multiple sessions<\/span><\/span>\n<\/p>\n<p>\n\t<br \/>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>&nbsp;&nbsp;Implicit Objects:<\/strong><br \/>\n\t&nbsp;&nbsp;&nbsp;We have 9 implicit object in JSP, container creates all these implicit objects for you. you can use simply with out creating.<br \/>\n\t&nbsp;&nbsp;&nbsp;1)out<br \/>\n\t&nbsp;&nbsp;&nbsp;2)request &nbsp;(javax.servlet.http.httpServletRequest)<br \/>\n\t&nbsp;&nbsp;&nbsp;3)response ()<br \/>\n\t&nbsp;&nbsp;&nbsp;4)session &nbsp;(HttpSession)<br \/>\n\t&nbsp;&nbsp;&nbsp;5)Application (ServletContext)<br \/>\n\t&nbsp;&nbsp;&nbsp;6)Page&nbsp;<br \/>\n\t&nbsp;&nbsp;&nbsp;7)Config (ServletConfig)<br \/>\n\t&nbsp;&nbsp;&nbsp;8)PageContext (Javax.servlet.jsp.PageContext)<br \/>\n\t&nbsp;&nbsp;&nbsp;9)Exception (JspException)<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;&nbsp;&nbsp;All the remaining implict objects will be created using pageContext<\/span><\/span>\n<\/p>\n<p>\n\t<br \/>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>Custom Tag library:<\/strong><br \/>\n\t&nbsp;&nbsp;&lt;%@ taglib uri=&quot;bellinfo.com&quot; prefix=&quot;koka&quot;%&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;&nbsp;&lt;koka:hello name=&quot;siva&quot; email=&quot;siva@gmail.com&quot;\/&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">o\/p : Hello, Siva!! Nice work, your email siva@gmail.com is accepted.<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">2)Web.xml<br \/>\n\t&lt;taglib&gt;&nbsp;<br \/>\n\t&nbsp;&nbsp;&lt;tlib-uri&gt;&lt;\/tlib-uri&gt;<br \/>\n\t&nbsp;&nbsp;&lt;tlib-location&gt;&lt;\/tlib-location&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">3)Write the .tld file<br \/>\n\t4)Implement the tagHandle class<\/span><\/span>\n<\/p>\n<p>\n\t<br \/>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>JSP JSTL Tags<\/strong><\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&lt;dependency&gt;<br \/>\n\t&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;groupId&gt;jstl&lt;\/groupId&gt;<br \/>\n\t&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;artifactId&gt;jstl&lt;\/artifactId&gt;<br \/>\n\t&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&lt;version&gt;1.2&lt;\/version&gt;<br \/>\n\t&lt;\/dependency&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<br \/>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>Core Tag Library<\/strong><br \/>\n\t&lt;%@taglib uri=&quot;http:\/\/java.sun.com\/jsp\/jstl\/core&quot; prefix=&quot;c&quot; %&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;&lt;c:forEach var = &quot;x&quot; begin = &quot;10&quot; end = &quot;15&quot;&gt;<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Item &lt;c:out value = &quot;${i}&quot;\/&gt;&lt;p&gt;<br \/>\n\t&nbsp;&lt;\/c:forEach&gt;<br \/>\n\t&nbsp;<br \/>\n\t&nbsp;&lt;c:forEach var=&quot;team&quot; items=&quot;${teams}&quot;&gt;<br \/>\n\t&nbsp; &nbsp; &lt;tr&gt;<br \/>\n\t&nbsp;&nbsp; &nbsp;&lt;td&gt;${team.id}&lt;\/td&gt;<br \/>\n\t&nbsp;&nbsp; &nbsp;&lt;td&gt;${team.name}&lt;\/td&gt;<br \/>\n\t&nbsp;&nbsp; &nbsp;&lt;td&gt;${team.rating}&lt;\/td&gt;<br \/>\n\t&nbsp;&nbsp; &nbsp;&lt;\/td&gt;<br \/>\n\t&nbsp; &nbsp;&lt;\/tr&gt;<br \/>\n\t&nbsp;&lt;\/c:forEach&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;&lt;c:set var=&quot;score&quot; value=&quot;25&quot;\/&gt;<br \/>\n\t&nbsp; &nbsp; &nbsp; &lt;c:if test = &quot;${salary &gt; 20}&quot;&gt;<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;p&gt;Match won with: &nbsp;&lt;c:out value = &quot;${score}&quot;\/&gt;&lt;p&gt;<br \/>\n\t&nbsp;&lt;\/c:if&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\">&nbsp;&lt;c:redirect url = &quot;http:\/\/www.photofuntoos.com&quot;\/&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>Functions Taglibrary<\/strong><br \/>\n\t&lt;%@ taglib uri = &quot;http:\/\/java.sun.com\/jsp\/jstl\/functions&quot; prefix = &quot;fun&quot;%&gt;<br \/>\n\t&nbsp; &nbsp; &nbsp;&lt;c:set var = &quot;sample&quot; value = &quot;I&#39;m learning jstl tags&quot;\/&gt;<br \/>\n\t&nbsp; &nbsp; &nbsp; &lt;c:if test = &quot;${fn:contains(sample, &#39;jstl&#39;)}&quot;&gt;<br \/>\n\t&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;p&gt;I&#39;m on track&lt;p&gt;<br \/>\n\t&nbsp; &nbsp; &nbsp; &lt;\/c:if&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>Formating Tag Libraries<\/strong><br \/>\n\t&lt;%@ taglib uri = &quot;http:\/\/java.sun.com\/jsp\/jstl\/fmt&quot; prefix = &quot;fmt&quot;%&gt;<br \/>\n\t&lt;c:set var = &quot;number&quot; value = &quot;35454&quot; \/&gt;<br \/>\n\t&nbsp; &nbsp;&lt;fmt:formatNumber value = &quot;${number}&quot; &nbsp;type = &quot;currency&quot;\/&gt;&lt;\/p&gt;<br \/>\n\t&nbsp; &nbsp;&lt;fmt:setLocale value = &quot;en_US&quot;\/&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>XML Tag libraries<\/strong><br \/>\n\t&lt;%@ taglib uri = &quot;http:\/\/java.sun.com\/jsp\/jstl\/xml&quot; prefix = &quot;xml&quot;%&gt;<\/span><\/span>\n<\/p>\n<p>\n\t<span style=\"font-size:14px;\"><span style=\"font-family:verdana,geneva,sans-serif;\"><strong>SQL Tag libraries<\/strong><br \/>\n\t&lt;%@ taglib uri = &quot;http:\/\/java.sun.com\/jsp\/jstl\/sql&quot; prefix = &quot;sql&quot;%&gt;<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>JSP will be divided in to 3 sections Scriplets Expressions Declarations Life Cycle Of JSP: Translated servlet of a jsp contains the following&nbsp; jspInit() _jspService() jspDestroy() scriplet:&nbsp; &nbsp;.is a jsp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[9,2],"tags":[],"class_list":["post-149","post","type-post","status-publish","format-standard","hentry","category-advance","category-technology"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p70lnf-2p","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts\/149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=149"}],"version-history":[{"count":3,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts\/149\/revisions"}],"predecessor-version":[{"id":440,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=\/wp\/v2\/posts\/149\/revisions\/440"}],"wp:attachment":[{"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kaizen-koka.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}