Java

Scriplets

Aug 10, 2016

 Scriplets
 
 
-Any piece of code written in scriplet goes into service() method.
-Any complex or simple java code can be written in srciplet.
-Scriplet are meant for embedding java code.


-Scriplet never get translated.
-Hence a very simple but logical point to remember for scriplet is that Scriplet NEVER CAUSE TRANSITION ERRORS.
-Scriplet CAN BE BROKEN by STATIC content.<% Java Code %>
<%------------
------------
------------%>

-Nothing but pure java code goes in the dotted area.
-Any data declared become local to service().

TomJSP.jsp/j3
<html>
<body>
<%
      String name=request.getParameter ("name");
     if(name.equalsIgnoreCase("Tom"))
       {
          out.println("Hi Tom!!!");
          out.println("How are You ?");
       }
else
      {
         out.println("Who You ?");
         out.println("I don't know You");
      }
%>
</body>
</html>

URL:http://localhost:8080/learningkattaWebApp/j3 ?name=Tom


ScripletTomJSP.jsp/j4

 

<html>
<head> Scriplet Tom </head>
<body>
<b>
       A JSP to demonstrate that SCRIPLET can be broken by static content
</b>
<% String name=request.getParameter("name");
      if(name.equals("tom"))
          {
%>  
<b> 
Hi Tom! How are you ?  
</b>
<br>
<%
      }      
      else
     {  
%>
<b>
Who you ? I don't know you ?  <%= name %>
<%
       }





%>
</body>
</html>

 

Related Posts

language_img
Java

Expressions-JSP

Aug 10, 2016

language_img
Java

Include Directive

Aug 10, 2016

language_img
Java

Page Directive

Aug 10, 2016

Table Of Contents

;