Java Server Page

This page is http:// jan.newmarch.name /i18n/jsp/jsp.html
http://jan.newmarch.name:443/i18n/jsp/jsp.html
Count is blahbluh
Count is blah/usr/local/bin/access_count bluh

Introduction


MVC model


Basic JSP page


Deploying JSP pages


Request parameter

It is customary in a servlet to call the HttpServletRequest request parameter request. In JSP, that is its name:


<%@ page import="java.util.*,java.text.NumberFormat" %>
<%@ page contentType="text/html; charset=ISO-8859-1" %>
<html>
  <head>
    <title>Localized Numbers</title>
  </head>
  <body>
    <%
      Locale preferredLocale = request.getLocale();
      NumberFormat nf = NumberFormat.getInstance(preferredLocale);
      String numberStr = nf.format(123456.789);
     %>

    The number 123456.789 in the user's preferred locale is
    <%= numberStr %>
  </body>
</html>


Application objects


Forwarding control


Including another JSP page


Declarations


Mixing HTML and Java


Custom tags


Java Standard Tag Library


Standard tags

From The JavaTM Web Services Tutorial - Using JSTL
Area
Function
Tags
TLD
Prefix
Core
Expression Language Support
catch
out
remove
set
/jstl-c
c
Flow Control
choose
  when
  otherwise
forEach
forTokens
if
URL Management
import
  paramredirect
  param
url
  param
XML
Core
out
parse
set
/jstl-x
x
Flow Control
choose  when  otherwise
forEach
if
Transformation
transform
  param
I18n
Locale
setLocale
/jstl-fmt
fmt
Message formatting
bundle
message
  param
setBundle
Number and dateformatting
formatNumber
formatDate
parseDate
parseNumber
setTimeZone
timeZone
Database

setDataSource
/jstl-sql
sql
SQL
query
  dateParam
  param
transaction
update  dateParam
  param


Using JSTL tags


<%@ page contentType="text/html; charset=ISO-8859-5" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<fmt:formatNumber value="123456789" />

<c:if test="${1 == 1}">
  1 == 1 is true
</c:if>

<c:if test="${1 == 2}">
  1 == 2 is true
</c:if>

<br>

<c:set var="name" value="Fred" />
His name is ${name}

<br>
<c:forEach var="current" items="${headerValues}">
  Header key is: ${current.key},
  Value is: ${header[current.key]}
  <br>
</c:forEach>


Expression language


JSTL Implicit objects

The EL (expression language) has a number of inbuilt variables including


JSTL and i18n


Expression variables


Summary

Java Server Pages act as the presentation end of a backend web application. They allow a mix of HTML and Java in various ways

References


Jan Newmarch <jan@newmarch.name>
Last modified: Tue May 17 21:26:55 EST 2005
Copyright © Jan Newmarch, Monash University, 2007
Creative Commons License This work is licensed under a Creative Commons License
The moral right of Jan Newmarch to be identified as the author of this page has been asserted.