// Print the request headers
map = new TreeMap();
enames = request.getHeaderNames();
while (enames.hasMoreElements()) {
String name = (String
Tag: siteweb en jsp
JSP: Afficher HTML en JSP
<%@ page session="false" %>
<%
out.println("out
is an ");
out.println(out.getClass().getName());
out.println(" object.");
%>
JSP: Utilisation d’une source de données Préconfigurée
="c" uri="http://java.sun.com/jstl/core" %>
Using a Preconfigured DataSource
Address List
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: Utilisation d’une variable de la super classe en jsp
}
}
class aircraft extends vehicle
{
public void fly() throws java.io.IOException
{
JSP: Code Java pour la connexion à une base de données à partir d’une page jsp
) {
System.out.println("Error occurred " + e);
}
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ADDRESS");
}
JSP: Utilisation de la classe Calendar avec un Bean
ASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitat
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";
%>
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;
}
}
JSP: Se connecter à une base données pour la lecture
esultSet resultset =
statement.executeQuery("select * from tableName") ;
%>