Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out
Get this document free

JSP_SyntaxExamples

VIEWS: 99 PAGES: 3

									JSP Syntax card with examples
Element
Comment Declaration <%--

JSP Style
comment here ---%> Nil <%! int x=0; boolean bBool = false; %>

XML Style
<jsp:declaration> int x=0; boolean bBool =false; </jsp:declaration> <jsp:expression> bool </jsp:expression> <jsp:scriptlet> java code fragment; </jsp:scriptlet> <jsp:text> free flowing text </jsp:text> <jsp:directive.include file=” myPage.jsp” /> <jsp:directive.page language=’java’ | import=’ ’com.neon.pack.*’ | session=’true’ | ‘false’ buffer=’none’ | ‘8kb’ autoflush=’true’ | ‘false’ isThreadSafe=’true’ | ‘false’ info=’blah’ errorpage=’errro_blah.jsp’ isErrorPage=’true’ | ‘false’ /> <jsp:root xmlns:jsp=’http://java.sun.com/jsp/page’ à xmlns:me=’/taglib/myTag.tld > -- -- --- -- -</jsp:root> -- same as jsp --

Expression

<%= bool %> Any java primitive or string etc. <% java code fragment; %> Nil

Scriptlet

Text

Include Directive Page Directive bold = default

<%@ include file=”myPage.jsp” %> <%@ page language=’java’ | import=’com.neon.pack.*’ | session=’true’ | ‘false’ buffer=’none’ | ‘8kb’ autoflush=’true’ | ‘false’ isThreadSafe=’true’ | ‘false’ info=’blah’ errorpage=’errro_blah.jsp’ isErrorPage=’true’ | ‘false’ %> <%@ taglib uri=’/tagdir/myTag.tld’ prefix=’me’ %>

Taglib Directive

Tag usage

<me:tester year=’2003’ /> <me:tagger age=’38’ > jsp body -- -- -</ me:tagger > <jsp:forward page=’myPage.jsp’ /> <jsp:forward page=’<%= expression %>’ /> <jsp:forward page=’myPage.jsp’ > <jsp:param name=’age’ value=’39’ /> <jsp:param name=’age’ value= ‘<%= expression %>’ /> </jsp:forward> <jsp:getProperty name=’addressBean’ property=’zip’ /> <jsp:include page=’myPage.jsp’ flush=’true|false’ /> <jsp:include page=’<%= expression %>’ flush=’true|false’ /> <jsp:include page=’myPage.jsp’ > <jsp:param name=’street’ value=’Goddard’>

<jsp:forward>

<jsp:forward page=’myPage.jsp’ /> <jsp:forward page=’%= expression %>’ /> <jsp:forward page=’myPage.jsp’ > <jsp:param name=’age’ value=’39’ /> <jsp:param name=’age’ value= ‘<%= expression %>’ /> </jsp:forward> <jsp:getProperty name=’addressBean’ property=’zip’ /> -- same --<jsp:include page=’%= expression %’ flush=’true|false’ /> -- same ---

<jsp:getProperty> <jsp:include>

</jsp:include> <jsp:include page=’myPage.jsp’ > <jsp:param name=’street’ value= ‘<%= expression %>’ /> </jsp:include> <jsp:useBean> <jsp:useBean id=’objAddress’ scope=’page’ class=’com.neon.OfficeAddressBean’ type=’com.neon.AddressBean’ /> <jsp:useBean beanName=’addressBean type=’com.neon.Address’ ’ / > <jsp:useBean beanName=’<%= exprr >’ type=’com.neon.Address’ ’ / > <jsp:setProperty name=’objBeanName’ property=’*’> <jsp:setProperty name=’objBeanName’ property=’city’ param=’myCity’ /> <jsp:include page=’myPage.jsp’ > <jsp:param name=’street’ value= ‘%= expression %’ /> </jsp:include>

-- same --

<jsp:setProperty>

<jsp:setProperty name=’objBeanName’ property=’city’ value=’Bracknell’ /> <jsp:setProperty name=’objBeanName’ property=’city’ value=’<%=expr%>’ /> <jsp:plugin Compulsory elements type=’bean | applet’ code=’class file name’ codebase=’class file dir name’ Optional elements name archive align height width hspace jreversion nspluginurl iepluginurl > <jsp:params> <jsp:param name=’namer’ value=’val’> </jsp:params> <jsp:fallback> message </jsp:plugin>

jsp:plugin

An area of confusion is when to use the include directive instead of the include action and vice versa. Include Directive <%@ include file= ‘myPage.jsp’ %> Translation time Fast File changes rarely Include Action <jsp:include page=’myPage.jsp’ /> Request time Slow File changes quite often Response of the included file is included The 2 files can [should] compile independently Variables between the 2 pages can be shared only through Different scopes e.g. context, session, request,etc.

Actual file is included
The 2 pages might not compile independently The variables can be shared

Produced by Yogen Joshi for VisualBuilder.com


								
To top