UP PREVIOUS NEXT   Technologies Internet et Education, © TECFA
  2. Introduction à JSP (Java Server Pages)

2. Introduction à JSP (Java Server Pages)

Principe de base:
Utilité:

2.1 Ecrire des pages JSP simples

Exemple 2-1: JSP simple (1)


  <BODY>
    <H1>JSP Test</H1>
		<ul>
      <%
      for (int i = 0; i < 5; i++) out.println ("<li>" + i);
      %>
		</ul>
  </BODY>

2.2 Faire une soupe HTML/Java plus mélangée

Exemple 2-2: JSP simple (2)

Dans les sections Java, il faut quoter les " qui doivent apparaître dans HTML ( \" )
int emphasize = 5;
for (int i = 0; i < size; i++) {
  out.println ("<li>");
  if (i == emphasize) out.println ("<b>");
  out.println(" \"
item" + i + ".jsp\"
 - item number " + i);
  if (i == emphasize) out.println ("</b>");
}
On peut mélanger variables Java et strings HTML
<% int font_size = 20; String color = "red"; %>
......
<font color="<%=
 color %>
" size="<%
= font_size %>
"> Youppie ! </font>
......
 

2.3 Gestion des erreurs

Page error.jsp
<%@ page isErrorPage="true"  %>
The name of the exception was:<%= exception.toString() %>
The message of the exception was: <%= exception.getMessage() %>
The stack trace was:<br>
    <% 
	 java.io.PrintWriter outstream = new java.io.PrintWriter(out);
     exception.printStackTrace(outstream); %>
Page jsp normale:
<%@ page errorPage="error.jsp" %>

UP PREVIOUS NEXT -- TIE