JSP Programming (ppt)

clangpotatoSoftware and s/w Development

Oct 28, 2013 (3 years and 9 months ago)

70 views

JSP Programming

Web Programming


Web Programming


Web Programming


HTML Text


<H1>HELLO</H1>


HTML Comments


<!
--

HTML Comment
--
>


JSP Comment



<%
--

JSP Comment
--
>


JAVA Code comment



<% //Java Comment %>

Web Programming


Web Programming


request


HttpServletRequest


response


HttpServletResponse


out


Writer ,
JSPWriter


session


HttpSession


application


ServletContext

,
getServletContext
( )

Web Programming


Web Programming

Web Programming







Control the translation of the JSP page into a
servlet


Do not generate output


Often appear on the first lines of a JSP page


Three basic types:
page, include
, and
taglib

Web Programming


Web Programming


Includes a static object at JSP page translation time


The content is parsed by JSP translator


Changes to included pages might not trigger
automatic recompilation of the JSP page


Web Programming


Format

<%@ include file=“Relative URL” %>


Purpose


To reuse JSP content in multiple pages,
where JSP
content affects main page


Notes


Servers are not required to detect changes to the
included file, and in practice they don't.


Thus, you need to change the JSP files whenever
the included file changes.


Web Programming


Format

<
jsp:include

page=“Relative URL” />


Purpose


To reuse JSP, HTML, or plain text content


To permit updates to the included content without
changing the main JSP page(s)


Notes


JSP content cannot affect main page: only
output of
included JSP page is used


Relative URLs that starts with slashes are interpreted
relative to the Web app, not relative to the server
root.


You are permitted to include files from WEB
-
INF


Web Programming


Web Programming


Create Master page by using
<jsp:include> or <%@ page file %>

Web Programming

Header.jsp

Menu.jsp

Content.jsp

Footer.jsp


Format

<%@ page session=“true”%> <%
--
Default%>

<%@ page session=“false”%>


Purpose


To designate that page not be part of a session


Notes


By default, it is part of a session


Saves memory on server if you have a high
-
traffic site


Web Programming


Get data and save in session


<%



String name = request.getParameter( "username" );



session.setAttribute( "theName", name );

%>

Web Programming


Use session


<HTML>

<BODY>


Hello, <%= session.getAttribute( "theName" ) %>

</BODY>


</HTML>

Web Programming

Web Programming