Java Server Pages (JSP)

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 22

Java Server Pages(JSP)

Sun Microsystems
Java Server Pages(JSP)
Methods
jspInit()
jspDestroy()
_jspService()
Java Server Pages(JSP)
• Directives
• page
• include
• taglib
Page Directive
Attribute Default Value
• Language Java
• Extends -
• Import -
• Session true
• Buffer 8k
• autoFlush true
• isThreadSafe false
• isErrorPage false
• errorPage -
• contentType text/html
• Usage : <%@ page language="java" %>
Include directive
• <%@ include file="file" %>

Tag directive
• uri
• tagPrefix
• Usage : <%@ taglib
uri="http://www.myserver.com/mytag"
perfix="someprefix" />
Scripting elements
1. Declarations
<%!

%>
2. Scriptlets
<%

%>
3. Expressions
<%= Object.toString() %>
Standard Actions
• <jsp:useBean>

• <jsp:setProperty>

• <jsp:getProperty>

• <jsp:param>

• <jsp:include>

• <jsp:forward>

• <jsp:plugin>
jsp:useBean
• id
• Scope
• class
• beanName
• Usage : <jsp:useBean id=“bid” class=“Abc”/>
jsp:setProperty / jsp:getProperty
• name

• Property
• Usage : <jsp:setProperty
name=“abc” property=“propertyName”>
<jsp:param …./>
</jsp:setProperty>
jsp:param
• name
• Value
• Usage : <jsp:param
name=“paramName” value=“paramValue”>
jsp:include
• page
• Flush
• Usage : <jsp:include
page=“URL” flush=“true/false”>
jsp:forward
• Page
• Usage : <jsp:forward page=“URL” />
Implicit Objects

JavaServerPages
Implicit Objects

page javax.servlet.jsp.HttpJspPage
config javax.servlet.ServletConfig
request javax.servlet.http.HttpServletRequest
response javax.servlet.http.HttpServletResponse
out javax.servlet.jsp.JspWriter
session javax.servlet.http.HttpSession
application javax.servlet.ServletContext
pageContext javax.servlet.jsp.PageContext
exception java.lang.Throwable
config
• getInitParameterNames()
– Retrieves the names of all Initialization
parameters
• getInitParameter(String)
– Retrieves the value of the named initialization
parameter
request
• getParameterNames()
– Returns the names of all request parameters
• getParameter(String)
– Returns the first(or primary) value of a single
request parameter
• getParameterValues(String)
– Retrieves all of the values for a single request
parameter
• getCookies()
– Retrieves all of the Cookies associated with the
request
response
• setContentType(String)
– Set the MIME type
• sendRedirect(String)
– Sends the response to the browser indicationg it
should request an alternate URL
• addCookie ()
– Add a Cookies associated with the response
out
• Print[ln](String)
– Sends the output to the browser
• clearBuffer()
– Clears the contents of the output buffer
• newLine()
– Writes a newline
• close()
– Closes the output Stream
session
• getValue(String)
– Returns the value of session item
• putValue(String, Object)
– Adds item to the session
• getId()
– Returns the Session ID
• getCreationTime()
– Returns the
• invalidate()
application
• getServerInfo()
– Returns the name and version of the servlet
container
• getMajorVersion()
– Returns the Major version of servlet API for the
servlet container
• getMinorVersion()
– Returns the Minor version of servlet API for
the servlet container
• getMimeType()
exception
• getMessage()
– Returns the descriptive error message
• printStackTrace(out)
– Prints the execution stack in effect when the
exception was thrown
• toString()
– Returns a string combining the class name of
the exception with its error message
ThankQ

You might also like