JSP: Utilisation de jspInit et jspDestroy


  
    Using jspInit and jspDestroy
  
  
    

Using jspInit and jspDestroy

    <%!     int number;     public void jspInit()     {       number = 5;     }     public void jspDestroy()     {       number = 0;     }     %>     <%     out.println("The number is " + number + "
");     %>                       

JSP: Utilisation de la recursion pour calculer la factorielle


  
    Using Recursion
  
  
    

Using Recursion

    <%!     int factorial(int n)     {         if (n == 1) {             return n;         }         else {             return n * factorial(n - 1);         }     }     %>     <%         out.println("The factorial of 6 is " + factorial(6));     %>                       

JSP: Créer une fonction en jsp

<%--
  Copyright (c) 2002 by Phil Hanna
  All rights reserved.
  
  You may study, use, modify, and distribute this
  software for any purpose provided that this
  copyright notice appears in all copies.
  
  This software is provided without warranty
  either expressed or implied.
--%>
<%!
   public int sum(int a, int b)
   {
      return a + b;
   }
%>
2 + 2 = <%= sum(2, 2) %>
           
       

JSP: Génerer des codes HTML à partir d’un code JSP

<%@ page language="java" %>

  JSP Example
  
    

Quadratic Equation: y = x^2

               xy         <%            for (int i=0; i<10; i++)             out.print("" + i + "" + (i*i) + "");         %>