JSP: Afficher HTML en JSP

<%@ page session="false" %>
<%
   out.println("out is an ");
   out.println(out.getClass().getName());
   out.println(" object.");
%>
           
       

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: Comment utilisation de constructeur d’un Bean

//Fichier: index.jsp

    
        Using a Constructor
    
    
    

Using a Constructor

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