Upload
kelley-hensley
View
222
Download
0
Embed Size (px)
DESCRIPTION
CSI 3125, Preliminaries, page 3 JSP (Java Server Pages) Html+java=jsp In servlet need 3 file html, web.xtml,java Next technology of servlet is jsp Inserted of 3 file in servlet jsp with 1file JSp ->.jsp extension Executed on the webserver apache tomcat, web logic, sphere… Used for UI/front end/ display purpose (multipurpose)
Citation preview
CSI 3125, Preliminaries, page 1
JSP (Java Server Pages)
CSI 3125, Preliminaries, page 2
JSP (Java Server Pages) • JavaServer Pages (JSP) is a server-side
programming technology that enables the creation of dynamic, platform-independent method for building Web-based applications.
• JSP have access to the entire family of Java APIs, including the JDBC API
CSI 3125, Preliminaries, page 3
JSP (Java Server Pages) • Html+java=jsp• In servlet need 3 file html, web.xtml,java• Next technology of servlet is jsp
Inserted of 3 file in servlet jsp with 1fileJSp ->.jsp extension
• Executed on the webserver apache tomcat, web logic, sphere…
• Used for UI/front end/ display purpose (multipurpose)
CSI 3125, Preliminaries, page 4
JSP (Java Server Pages) • JSP execution Procedure• When JSP compile (using JSP compiler)-->
converted to servlet file• Servlet file is compiled and generate. class file• This class file is loaded into memory and
executed by JVM
CSI 3125, Preliminaries, page 5
JSP (Java Server Pages) • JSP LIFE CYCLE• • Same as Servlet life cycle init(), service(), destroy();• JSP has • JspInit() - is called when JSP is loaded in memory• jspService(); - is called when the client request• jspDestroy(); - invoked when JSP is removed from
memory• • not need to write these methods they automatically run
CSI 3125, Preliminaries, page 6
JSP (Java Server Pages) • There are five types of JSP tags: • Directive tag • Comment Tag • Expression tag • Declaration statement tag • Scriplet tag
CSI 3125, Preliminaries, page 7
JSP (Java Server Pages) • DIRECTIVES • To perform a specific task• They have the general form: • <%@ directive-name [attribute="value"
attribute="value" ...] %> • There are diff standard directives • page • include
CSI 3125, Preliminaries, page 8
JSP (Java Server Pages) DIRECTIVES Tag • The page Directive • The page directive apply different properties for the page • syntax: • <%@ page [attribute="value" attribute="value" ...] %> • Following are names of some of important the attributes of
the page directive used in JSP • import: : This attribute imports the java packages and it's
classes .• Eg: <%@ page import="java.util.*" %> • contentType: This attribute specifies the type i.e. used for the
JSP response • Eg:<%@ page contentType="text/plain" %>
CSI 3125, Preliminaries, page 9
JSP (Java Server Pages) DIRECTIVES Tag • The include directive• The include directive merges the contents of
another file like a #include C preprocessor directive.
• The syntax is • <%@ include file="filename" %> • where filename can specify with path. • Eg: • <%@ include file="/doc/legal/disclaimer.html" %>
CSI 3125, Preliminaries, page 10
JSP (Java Server Pages) Comment Tag <%- - This is a hidden JSP comment - -%>Expression tag • <%= expression %> • The expression can have any data value• Eg:<%= new java.util.Date() %>
CSI 3125, Preliminaries, page 11
JSP (Java Server Pages) Declaration statement tag Declare variables and functionsEg: <%! private int example = 0 ; private int test = 5 ; %> • SCRIPTLETS • A scriptlet consists of one or more valid Java statements • Ie java code• <% Java Code %> • Eg: <% System.out.println( "Evaluating date now); %>
CSI 3125, Preliminaries, page 12
JSP (prog) <html><body><br><%@ page import=" java.util.*"%><%@ page contentType="text/html" %> <%@ include file="popo.jsp" %>
<%--will not display comment line --%>
<%! int a=10;int b=20;%>
<% out.println("sum of "+a+" and "+b+" = "+(a+b));%>
</body></html>
CSI 3125, Preliminaries, page 13
JSP ( Method def and calling prog) <html><body><%! int add(int x,int y){ return (x+y);}%>Calling Method <%=add(10,20)%>
</body></html>
CSI 3125, Preliminaries, page 14
JSP (Java Server Pages)