Docstoc

JSP_SyntaxExamples

Document Sample
JSP_SyntaxExamples Powered By Docstoc
					                               JSP Syntax card with examples
Element                             JSP Style                                        XML Style
Comment             <%--     comment here                ---%>       Nil
Declaration         <%! int x=0; boolean bBool = false; %>           <jsp:declaration>
                                                                        int x=0;
                                                                        boolean bBool =false;
                                                                     </jsp:declaration>
Expression          <%= bool %>                                      <jsp:expression>
                    Any java primitive or string etc.                   bool
                                                                     </jsp:expression>
Scriptlet           <%                                               <jsp:scriptlet>
                    java code fragment;                                 java code fragment;
                    %>                                               </jsp:scriptlet>
Text                Nil                                              <jsp:text>
                                                                        free flowing text
                                                                     </jsp:text>
Include Directive   <%@ include file=”myPage.jsp” %>                 <jsp:directive.include file=” myPage.jsp” />
Page Directive      <%@ page                                         <jsp:directive.page
                      language=’java’ |                                 language=’java’ |
bold = default        import=’com.neon.pack.*’ |                        import=’ ’com.neon.pack.*’ |
                      session=’true’ | ‘false’                          session=’true’ | ‘false’
                      buffer=’none’ | ‘8kb’                             buffer=’none’ | ‘8kb’
                      autoflush=’true’ | ‘false’                        autoflush=’true’ | ‘false’
                      isThreadSafe=’true’ | ‘false’                     isThreadSafe=’true’ | ‘false’
                      info=’blah’                                       info=’blah’
                      errorpage=’errro_blah.jsp’                        errorpage=’errro_blah.jsp’
                      isErrorPage=’true’ | ‘false’                      isErrorPage=’true’ | ‘false’
                    %>                                               />
Taglib Directive    <%@ taglib uri=’/tagdir/myTag.tld’               <jsp:root
                    prefix=’me’ %>                                       xmlns:jsp=’http://java.sun.com/jsp/page’
                                                                     à xmlns:me=’/taglib/myTag.tld >
                                                                         -- -- --
                                                                         -- -- --
                                                                     </jsp:root>
Tag usage           <me:tester year=’2003’ />                        -- same as jsp --

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

                    <jsp:include page=’myPage.jsp’ >              <jsp:include page=’myPage.jsp’ >
                     <jsp:param name=’street’ value=               <jsp:param name=’street’ value=
                                        ‘<%= expression %>’                           ‘%= expression %’ />
                    />                                            </jsp:include>
                     </jsp:include>

<jsp:useBean>       <jsp:useBean id=’objAddress’                  -- same --
                    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>   <jsp:setProperty name=’objBeanName’

                    property=’*’>

                    <jsp:setProperty name=’objBeanName’
                               property=’city’ param=’myCity’
                    />


                    <jsp:setProperty name=’objBeanName’
                              property=’city’ value=’Bracknell’
                    />

                    <jsp:setProperty name=’objBeanName’
                         property=’city’ value=’<%=expr%>’
                    />
jsp:plugin          <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>
An area of confusion is when to use the include directive instead of the include action and vice versa.

Include Directive                                       Include Action
                                                        <jsp:include page=’myPage.jsp’ />
<%@ include file= ‘myPage.jsp’ %>                       Request time
Translation time                                        Slow
Fast                                                    File changes quite often
File changes rarely                                     Response of the included file is included
Actual file is included                                 The 2 files can [should] compile independently
The 2 pages might not compile independently             Variables between the 2 pages can be shared only
The variables can be shared                             through
                                                        Different scopes e.g. context, session, request,etc.




Produced by Yogen Joshi for VisualBuilder.com

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:1
posted:9/2/2012
language:
pages:3
Description: Articles useful for College Students.