JSP: Exemple d’utilisation de Bean en JSP

//////////////////////////////////////       
//Fichier: index.jsp       
       
<%@ page import="beans.MessageBean" %>

  
    Using a JavaBean
  
  
    

Using a JavaBean

    <% MessageBean m = new MessageBean(); %>     The message is: <%= m.msg() %>     ////////////////////////////////////////////////// //Fichier: MessageBean.java package beans; public class MessageBean {     public MessageBean()      {     }     public String msg()      {         return "Hello from JSP!";     } }                    

JSP: Boucle while en jsp


  
    Finding Reciprocals
  
  
    

Finding Reciprocals

    <%         double values[] = {4, 3, 2, 1, 0, 1, 2, 3, 4};         int i = 0;         while (values[i] != 0){             out.println("The reciprocal = " + 1 / values[i++] + ".
");         }      %>                       

JSP: Affichage des cookies dans une page JSP

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

Cookie display

Here are all the Available Cookies

    : Object=, value=                             

JSP: Exemple de déclaration de Tag

<%!   String nom = "Mark";   String date = "28th April, 2004"; %>

  Declaration Tag Example
  
    This page was last modified on <%= date %> by <%= nom %>.
  

           
       

JSP: Modifier les Attributs de PageContext d’une page JSP

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%
  synchronized (pageContext) {
    Class thisClass = getClass();
  // session.setAttribute("thisClass", thisClass);
    pageContext.setAttribute("thisClass", thisClass, PageContext.PAGE_SCOPE);
    System.out.println("Stored reference");
    Class theClass = (Class) pageContext.getAttribute("thisClass", PageContext.PAGE_SCOPE);
    System.out.println("The retrieved reference is " + theClass);
  }
%>

  
    The class that instantiated this JSP is .
  

           
       

JSP: Créer une table

nection.createStatement();
                String command = "CREATE TABLE Employees (ID INTEGER, Name CHAR(50));";
                statement.executeUpdate(comma

JSP: Afficher les Propriétés du système

ellpadding="3" cellspacing="0">
<%
   final String[] propNames = {
      "java.awt.printerjob",
      "java.class.path",
      "java.class.version",
      "java