Java Server Pages (JSP)
Why JSP Technology :Servlets are good at running logic Not so good at producing large amounts of output
JSP pages are great at producing lots of textual output Not so good at lots of logic.
“JSP page” is Mixture of text, Script and directives
Text could be text/ html, text/ xml or text/ plain
“JSP engine”
'Compiles’ page to servlet Executes servlet’s service() method
Sends text back to caller
Page is Compiled once and Executed many times
Anatomy of a JSP
<%@ page language=“java” content“text/html” %>
<html>
<body bgcolor=“white”>
<jsp:useBean id=“greeting” “com.pramati.jsp.beans.GreetingBean”>
<jsp:setProperty name=“greeting” property=“*”/>
</jsp:userBean>
The following information was saved:
User Name:
<jsp:getProperty name=“greeting” property=“userName”/>
Welcome!
</body>
</html>
JSP Elements
•Directive Elements:– Informationabout the page
–Remains same between requests
–E.g., scripting language used
•Action Elements : –Take action based on info required at request-time
•Standard
•Custom (Tags and Tag Libraries)
•Scripting Elements
–Add pieces of code to generate output based on conditions
Directives
•Global information used by the “JSP engine”
•Of form <%@ directive attr_ list %>
•Or <jsp: directive. directive attr_ list />
–Directive could be
•Page
•Include
•Taglib
–E. g.,
<%@ page info=“ written by DevelopMentor” %>
<jsp: directive. page import=“ java. sql.*” />
<%@ include file =“\ somefile. txt” %>
<%@ taglib uri = tags prefix=“ foo” %>
Actions Within a JSP Page
•Specifies an action to be carried out by the “JSP engine”
•Standard or custom
–Standard must be implemented by all engines
–Custom defined in tag libraries
•Standard actions ‘scoped’ by ‘jsp’ namespace
•Have name and attributes
<jsp: useBean id=“ clock” “ java.util.Date” />
<ul> The current date at the server is:
<li> Date: <jsp: getProperty name=“clock” property=“date” />
<li> Month: <jsp: getProperty name=“clock” property=“month” />
</ul>
JSP pages are great at producing lots of textual output Not so good at lots of logic.
“JSP page” is Mixture of text, Script and directives
Text could be text/ html, text/ xml or text/ plain
“JSP engine”
'Compiles’ page to servlet Executes servlet’s service() method
Sends text back to caller
Page is Compiled once and Executed many times
Anatomy of a JSP
<%@ page language=“java” content“text/html” %>
<html>
<body bgcolor=“white”>
<jsp:useBean id=“greeting” “com.pramati.jsp.beans.GreetingBean”>
<jsp:setProperty name=“greeting” property=“*”/>
</jsp:userBean>
The following information was saved:
User Name:
<jsp:getProperty name=“greeting” property=“userName”/>
Welcome!
</body>
</html>
JSP Elements
•Directive Elements:– Informationabout the page
–Remains same between requests
–E.g., scripting language used
•Action Elements : –Take action based on info required at request-time
•Standard
•Custom (Tags and Tag Libraries)
•Scripting Elements
–Add pieces of code to generate output based on conditions
Directives
•Global information used by the “JSP engine”
•Of form <%@ directive attr_ list %>
•Or <jsp: directive. directive attr_ list />
–Directive could be
•Page
•Include
•Taglib
–E. g.,
<%@ page info=“ written by DevelopMentor” %>
<jsp: directive. page import=“ java. sql.*” />
<%@ include file =“\ somefile. txt” %>
<%@ taglib uri = tags prefix=“ foo” %>
Actions Within a JSP Page
•Specifies an action to be carried out by the “JSP engine”
•Standard or custom
–Standard must be implemented by all engines
–Custom defined in tag libraries
•Standard actions ‘scoped’ by ‘jsp’ namespace
•Have name and attributes
<jsp: useBean id=“ clock” “ java.util.Date” />
<ul> The current date at the server is:
<li> Date: <jsp: getProperty name=“clock” property=“date” />
<li> Month: <jsp: getProperty name=“clock” property=“month” />
</ul>