<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
< title> Insert title here </title >
<link href="css/index.css" rel="stylesheet" type="text/css">
</head>
<body>
Hello <br /> My darling.
<%-- SCRIPTING ELEMENTS START --%>
<% //scriplet
out.println("-= ## =-");
JspWriter jw = out;
response.getWriter().write("*-*-*-*-*");
%>
<%= //expression
new Integer(50).toString()
%>
<%! //declaration
/*
public void init(){
}
public void destroy(){
}*/
public void jspInit(){
Servlet s = (Servlet)this;
JspPage jp =(JspPage)this;
HttpJspPage hjp = (HttpJspPage)this;
System.out.println("jspInit()");
}
public void jspDestroy(){
System.out.println("jspDestroy()");
}
%>
<%-- SCRIPTING ELEMENTS END --%>
<!-- HTML Comment -- >
<%-- JSP Comment --% >
<jsp:useBean id="myBean" scope="application" class="java.lang.String"></jsp:useBean></body></html>EL (Expression Language) was introduces in JSP 2.0!
Some interesting jsp code to generate colored effects:
<% for(int i=0; i< 4095; i++){%>
<div style="
background-color: #<%=Integer.toHexString(0x1000|i).substring(1)%>;
height:1px;"></div>
<%}%>
Form with drop-down list that save its state:
<form action="index.jsp" method="get">
<select size="1" <%-- multiple="multiple" --%> name="join">
<option <%= request.getParameter("join") == null ? "selected" : "" %> ></option>
<option <%= request.getParameter("join") != null && request.getParameter("join").equals("right") ? "selected" : "" %> value="right">right</option>
<option <%= request.getParameter("join") != null && request.getParameter("join").equals("left") ? "selected" : "" %> value="left">left</option>
<option <%= request.getParameter("join") != null && request.getParameter("join").equals("full") ? "selected" : "" %> value="full">full</option>
</select>
<input type="submit" value="sub">
</form>