Friday, October 7, 2016

JSP Quick Reference

JSP Quick Reference Card

What is JavaServer Pages?

JavaServer Pages JSP is a technology for developing web pages that support dynamic content
which helps developers insert java code in HTML pages by making use of special JSP tags, most of
which start with <% and end with %>.

A JavaServer Pages component is a type of Java servlet that is designed to fulfill the role of a user
interface for a Java web application. 

Performance is significantly better because JSP allows embedding Dynamic Elements in HTML Pages

JSP are always compiled before it's processed by the server

JavaServer Pages are built on top of the Java Servlets API,

JSP pages can be used in combination with servlets that handle the business logic,

Default scripting language
The scripting language of a JSP page defaults to Java.
Insert the following line in a JSP page to configure the page to use JavaScript:
<%@ page language = "javascript" %>

Using white space
White space contained within the template code is returned to the client as it was entered in the JSP.

Quoting attribute values
Quote attribute values, using either single or double quotes, to all JSP elements.
For example: <%@ page contentType = "text/plain" %>

Writing comments for the JSP
A JSP comment is not output to the client as part of the JSP page’s output.
 <%-- Comment string... --%>

Outputting comments to the client
HTML comments are output to the client.

page
Defines page-wide attributes. <%@ page attribute="value" ... %> attributes, with default values, are: attribute = language="java" | session="true" | contentType=text/html;charset="ISO-8859-1" | import="package(s)" | buffer="8kb" | autoflush="true" | isThreadSafe="true" | info="text_string" | errorPage="relativeURL" | isErrorpage="true" | extends="class_name" value = a string literal in single or double quotes.

include
Inserts text into a JSP page. <%@ include file = "path" ... %>

taglib
Defines a custom tag library used by a JSP page. <%@ taglib uri="tagLibraryURI" prefix="tagPrefix" %> After the taglib directive, reference the custom tags using the syntax: ...

declaration
Creates page-wide definitions such as variables.
<%! declaration %>
 Example: <%! private String foo = null; public String getFoo() {return this.foo;} %>

scriptlet
Contains a block of scripting code. A JSP page can contain multiple blocks of scripting code.
<% script code %>
 Example: <% String greeting = request.getParameter("Greeting"); out.println(greeting); %>

expression
Defines statements evaluated on the server before sending the page output to the client.
 <%= expression %>
 Example: <%= myVar1%>

jsp:include
Call one JSP page from another. Upon completion, the destination page returns control to the calling page. ...

jsp:forward
Calls one JSP page from another. Execution of the calling page is terminated by the call.  


HTML Comments

Sent to the client in the viewable page source.

JSP Comments (Not Sent to Client)
<%-- comment--%>
Comments in JSP file.

// comment Comment in scriplet part of JSP file.

Declaration
<%! declaration %>
Creates a global variable or method.

Expression
<%= expression %>
 Statements evaluated on the server before the page is outputted to  the client.

Page Directive
<%@ directive %>
Attributes that apply to  the entire page.

Scriplet
<% code fragment of one or more lines %>
Contains a block of scripting code which is executed when the page is generated.

Taglib Directive
<%@ taglib uri="URIToTagLibrary" prefix="tagPrefix" %>
Defines a tag library and prefix for tags used in a JSP page.

jsp:include Includes a file at the time the page is requested
jsp:useBean Finds or instantiates a JavaBean
jsp:setProperty         Sets the property of a JavaBean
jsp:getProperty Inserts the property of a JavaBean into the output
jsp:forward Forwards the requester to a new page
jsp:pluginGenerates browser-specific code that makes an OBJECT or EMBED tag for the Java plugin
jsp:element Defines XML elements dynamically.
jsp:attribute Defines dynamically defined XML element's attribute.
jsp:body         Defines dynamically defined XML element's body.
jsp:text         Use to write template text in JSP pages and documents.

JSP Implicit Objects:
request         This is the HttpServletRequest object associated with the request.
response         This is the HttpServletResponse object associated with the response to the client.
out                 This is the PrintWriter object used to send output to the client.
session         This is the HttpSession object associated with the request.
application This is the ServletContext object associated with application context.
config         This is the ServletConfig object associated with the page.
Exception The Exception object allows the exception data to be accessed by designated JSP.
pageContext This encapsulates use of server-specific features like higher performance JspWriters.
page This is simply a synonym for this, and is used to call the methods defined by the translated servlet class.

Default scripting language
The scripting language of a JSP page defaults to Java.
Insert the following line in a JSP page to configure the page to use JavaScript:
<%@ page language = "javascript" %>

Using white space
White space contained within the template code is returned to the client as it was entered in the JSP.

Quoting attribute values
Quote attribute values, using either single or double quotes, to all JSP elements. For example:
<%@ page contentType = "text/plain" %>

Writing comments for the JSP
A JSP comment is not output to the client as part of the JSP page’s output.
<%-- Comment string... --%>

Outputting comments to the client
HTML comments are output to the client.


page
Defines page-wide attributes.

<%@ page attribute="value" ... %>
attributes, with default values, are:
attribute = language="java" | session="true"| contentType=text/html;charset="ISO-8859-1"
| import="package(s)" | buffer="8kb"| autoflush="true" | isThreadSafe="true"
| info="text_string" | errorPage="relativeURL"| isErrorpage="true" | extends="class_name"

value = a string literal in single or double quotes.

include
Inserts text into a JSP page.
<%@ include file = "path" ... %>

taglib
Defines a custom tag library used by a JSP page.
<%@ taglib uri="tagLibraryURI"
prefix="tagPrefix" %>
After the taglib directive, reference the custom tags using the syntax:

...


declaration
Creates page-wide definitions such as variables.
<%! declaration %>
Example:
<%! private String foo = null;
public String getFoo() {return this.foo;} %>

scriptlet
Contains a block of scripting code. A JSP page can contain multiple blocks of scripting code.
<% script code %>
Example:
<% String greeting = request.getParameter("Greeting");
out.println(greeting); %>

expression
Defines statements evaluated on the server before sending the page output to the client.
<%= expression %>
Example :<%= myVar1%>

jsp:include
Call one JSP page from another. Upon completion, the
destination page returns control to the calling page.


value="paramValue" /> ...


jsp:forward
Calls one JSP page from another. Execution of the calling page is terminated by the call.


value="paramValue" /> ...


jsp:plugin
Enables you to invoke an applet on a client browser.
type="bean|applet"
code="objectCode"
codebase="objectCodebase"
{ align="alignment" }
{ archive="archiveList" }
{ height="height" }
{ hspace="hspace" }
{ jreversion="jreversion" }
{ name="componentName" }
{ vspace="vspace" }
{ width="width" }
{ nspluginurl="url" }
{ iepluginurl="url" } >
{
{ value="paramValue" /> }+

}{ arbitrary_text

} >
The elements in brackets ({}) are optional.

jsp:useBean
Defines an instance of a Java bean.


body

typespec is any one of the following:
class="className" | class="className" | beanName="beanName" type=" typeName"

jsp:setProperty
Sets the value of one or more properties in a bean.

prop_expr has one of the following forms:
property="*" |
property="propertyName"|
property="propertyName" param="parameterName"|
property="propertyName" value="propertyValue"

jsp:getProperty
Writes the value of a bean property as a string to the out object.

See the corresponding Java object type for the available methods for these objects.

application
The servlet context obtained from the servlet configuration object.
Java type: javax.servlet.ServletContext

config
The ServletConfig object for the JSP page.
Java type: javax.servlet.ServletConfig

exception
The uncaught exception that resulted in the error page being invoked.
Java type: java.lang.Throwable

out
An object that writes into a JSP page’s output stream.
Java type: javax.servlet.jsp.JspWriter

pageContext
The page context for the JSP.
Java type: javax.servlet.jsp.PageContext

request
The client request.
Java type: javax.servlet.HttpServletRequest

response
The response to the client.
Java type: javax.servlet.HttpServletResponse

session
The session object created for the requesting client.
Java type: javax.servlet.http.HttpSession

No comments:

Post a Comment

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...