Friday, 16 March 2018

JSP Scripting elements

Scripting elements is used to insert java code inside the jsp. There are three types of scripting elements, they are
  • scriptlet tag
  • expression tag
  • declaration tag
Scriptlet tag
Scriptlet tag is used to execute java source code in JSP
Syntax:
<%  java source code %>  
Example 1:
<<html> 
<body> 
<% out.print("welcome to Learningpoint92"); %> 
</body> 
</html> 
   
    Example 2(taking value from user)
    Index.html
  <html> 
  <body> 
  <form action="demo.jsp"> 
   <input type="text" name="t1"> 
  <input type="submit" value="display"><br/> 
  </form> 
  </body> 
  </html> 
  demo.jsp
  <html>  
  <body>  
   <%  
   String name=request.getParameter("t1");  
   out.print("Heyy"+name);  
   %>  
  </form>  
  </body>  
  </html>  

   Expression tag
   It is used to print the values of variable or method.
   Syntax:
   <%=  statement %>  
  Note: Do not end your statement with semicolon in case of expression tag

  Example 1:
  demo.jsp
  <html>  
  <body>  
  <%= "welcome to Learningpoint92" %>  
  </body>  
  </html>  

  Example 2(taking value from user)
  Index.html
  <html> 
  <body> 
  <form action="demo.jsp"> 
   <input type="text" name="t1"> 
  <input type="submit" value="display"><br/> 
  </form> 
  </body> 

  </html>  
  demo.jsp
  <html>  
  <body>  
   <%= "Heyy "+request.getParameter("t1") %>     
   </body>  
   </html>  

  Declaration tag: 
  declaration tag is used to declare fields and methods.
  Syntax:
  <%!  field or method declaration %>  

  Example 1:
   demo.jsp
  <html>  
  <body>  
  <%! int x=20;%>  
   <%= "Value of the x is:"+x %>  
  </body>  
  </html>  

  Example 2:
  demo.jsp
    <html>  
    <body>  
     <%!   
    int add(int a,int b){  
    return a+b;  
   }  
    %>  
  <%= "Addition is:"+add(4,6) %>  
  </body>  
 </html>  


1 comment:

  1. Python is an open-source, high level, interpreted programming language which offers great opportunities for object-oriented programming. Choosing a python training program from Red Prism Group, which is best training institute for python in noida.

    ReplyDelete

Global Infrastructure and its components in AWS

You may operate your workloads wherever and however you choose with the AWS Global Infrastructure, and you'll use the same network, cont...