28. Explain JSP Basic Structure Items.

JSP Expression

  • <%= expression %>
  • Expression is evaluated and placed in output.
  • XML equivalent is
    <jsp:expression>
    expression
    </jsp:expression>
    .
  • Predefined variables are request,response,out,session,application,config, andpageContext (available in scriptlets also).

JSP Scriptlet

  • <% code %>
  • Code is inserted in service method.
  • XML equivalent is
    <jsp:scriptlet>
    code
    </jsp:scriptlet>
    .

JSP Declaration

  • <%! code %>
  • Code is inserted in body of servlet class, outside of service method.
  • XML equivalent is
    <jsp:declaration>
    code
    </jsp:declaration>
    .

JSP page Directive

  • <%@ page att=”val” %>
  • Directions to the servlet engine about general setup.
  • XML equivalent is
    <jsp:directive.page att="val"\>.
  • Legal attributes, with default values in bold, are:
    • import=”package.class
    • contentType=”MIME-Type
    • isThreadSafe=”true|false”
    • session=”true|false”
    • buffer=”sizekb|none”
    • autoflush=”true|false”
    • extends=”package.class
    • info=”message
    • errorPage=”url
    • isErrorPage=”true|false
    • language=”java”

JSP include Directive

  • <%@ include file=”url” %>
  • A file on the local system to be included when the JSP page is translated into a servlet.
  • XML equivalent is
    <jsp:directive.include
      file="url"\>
    .
  • The URL must be a relative one. Use the jsp:include action to include a file at request time instead of translation time.

JSP Comment

  • <%– comment –%>
  • Comment; ignored when JSP page is translated into servlet.
  • If you want a comment in the resultant HTML, use regular HTML comment syntax of <-- comment -->.

The jsp:include Action

  • <jsp:include page=”relative URL” flush=”true”/>
  • Includes a file at the time the page is requested.
  • If you want to include the file at the time the page is translated, use the page directive with theinclude attribute instead. Warning: on some servers, the included file must be an HTML file or JSP file, as determined by the server (usually based on the file extension).

The jsp:forward Action

  • <jsp:forward page=”relative URL“/>
  • Forwards request to another page.

The jsp:plugin Action

  • <jsp:plugin attribute=”value“*> … </jsp:plugin>
  • Generates OBJECT orEMBED tags, as appropriate to the browser type, asking that an applet be run using the Java Plugin.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: