Mic JSP 05
Mic JSP 05
Com
Copyright © 2003 IlmuKomputer.Com
Lisensi Dokumen:
Copyright © 2003 IlmuKomputer.Com
Seluruh dokumen di IlmuKomputer.Com dapat digunakan, dimodifikasi dan
disebarkan secara bebas untuk tujuan bukan komersial (nonprofit), dengan syarat
tidak menghapus atau merubah atribut penulis dan pernyataan copyright yang
disertakan dalam setiap dokumen. Tidak diperbolehkan melakukan penulisan ulang,
kecuali mendapatkan ijin terlebih dahulu dari IlmuKomputer.Com.
Biasanya pada Java objek dibuat dari class-nya. Pada JSP ada beberapa objek dimana user tidak
perlu membuatnya secara manual dari class-nya yang disebut Objek Implisit. Objek-objek
tersebut adalah :
• Objek request
• Objek response
• Objek pageContext
• Objek session
• Objek application
• Objek out
• Objek config
• Objek page
• Objek exception
Objek-objek ini hanya dapat digunakan di antara tag scriptlet dan ekspresi.
Objek request
Objek ini adalah hasil cetakan dari class javax.servlet.ServletRequest. Otomatis objek request
akan memiliki properti dan method yang dimiliki oleh class ServletRequest. Berikut adalah
daftar method-methodnya :
Method Summary
java.lang.Object getAttribute(java.lang.String name)
Returns the value of the named attribute as an Object,
or null if no attribute of the given name exists.
java.util.Enumeration getAttributeNames()
Returns an Enumeration containing the names of the
attributes available to this request.
java.lang.String getCharacterEncoding()
Returns the name of the character encoding used in the
body of this request.
int getContentLength()
Returns the length, in bytes, of the request body and
made available by the input stream, or -1 if the length is not
known.
java.lang.String getContentType()
Returns the MIME type of the body of the request, or
null if the type is not known.
ServletInputStream getInputStream()
Retrieves the body of the request as binary data using a
ServletInputStream.
java.util.Locale getLocale()
Returns the preferred Locale that the client will accept
content in, based on the Accept-Language header.
java.util.Enumeration getLocales()
Returns an Enumeration of Locale objects indicating,
in decreasing order starting with the preferred locale, the
locales that are acceptable to the client based on the Accept-
Language header.
java.lang.String getParameter(java.lang.String name)
Returns the value of a request parameter as a String,
or null if the parameter does not exist.
java.util.Map getParameterMap()
Returns a java.util.Map of the parameters of this request.
java.util.Enumeration getParameterNames()
Returns an Enumeration of String objects containing
the names of the parameters contained in this request.
java.lang.String[] getParameterValues(java.lang.String name)
Returns an array of String objects containing all of the
values the given request parameter has, or null if the
parameter does not exist.
java.lang.String getProtocol()
Returns the name and version of the protocol the request
uses in the form protocol/majorVersion.minorVersion, for
example, HTTP/1.1.
java.io.BufferedReader getReader()
Retrieves the body of the request as character data using
a BufferedReader.
java.lang.String getRealPath(java.lang.String path)
Deprecated. As of Version 2.1 of the Java Servlet API,
use
ServletContext.getRealPath(java.lang.String)
instead.
java.lang.String getRemoteAddr()
Returns the Internet Protocol (IP) address of the client
that sent the request.
java.lang.String getRemoteHost()
Returns the fully qualified name of the client that sent
the request.
RequestDispatcher getRequestDispatcher(java.lang.String path)
Returns a RequestDispatcher object that acts as a
wrapper for the resource located at the given path.
java.lang.String getScheme()
Returns the name of the scheme used to make this
request, for example, http, https, or ftp.
java.lang.String getServerName()
Returns the host name of the server that received the
request.
int getServerPort()
Returns the port number on which this request was
received.
boolean isSecure()
Returns a boolean indicating whether this request was
made using a secure channel, such as HTTPS.
void removeAttribute(java.lang.String name)
Removes an attribute from this request.
void setAttribute(java.lang.String name,
java.lang.Object o)
Stores an attribute in this request.
void setCharacterEncoding(java.lang.String env)
Overrides the name of the character encoding used in
the body of this request.
Contoh :
objek_request.jsp
IP Address : <%= request.getRemoteAddr() %>
<br>
Host : <%= request.getRemoteHost() %>
<br>
Server : <%= request.getServerName() %>
<br>
<%
out.println(“Port : “+request.getServerPort());
%>
Sumber : -
Objek response
Objek ini adalah hasil cetakan dari class javax.servlet.ServletResponse. Otomatis objek request
akan memiliki properti dan method yang dimiliki oleh class ServletResponse. Berikut adalah
daftar method-methodnya :
Method Summary
void flushBuffer()
Forces any content in the buffer to be written to the client.
int getBufferSize()
Objek pageContext
Objek ini merupakan cetakan dari class javax.servlet.jsp.PageContext.
Field Summary
static java.lang.String APPLICATION
Name used to store ServletContext in PageContext name
table.
static int APPLICATION_SCOPE
Application scope: named reference remains available in
the ServletContext until it is reclaimed.
Method Summary
abstract java.lang.Object findAttribute(java.lang.String name)
Searches for the named attribute in page, request,
session (if valid), and application scope(s) in order and
returns the value associated or null.
abstract void forward(java.lang.String relativeUrlPath)
Objek session
Objek ini merupakan cetakan dari class javax.servlet.http.HttpSession. Method yang dimiliki
oleh objek ini adalah sebagai berikut :
Method Summary
Objek application
Objek ini merupakan hasil cetakan dari class javax.servlet.ServletContext. method-method
yang dimilikinya adalah :
Method Summary
java.lang.Object getAttribute(java.lang.String name)
Returns the servlet container attribute with the given
name, or null if there is no attribute by that name.
java.util.Enumeration getAttributeNames()
Returns an Enumeration containing the attribute names
available within this servlet context.
ServletContext getContext(java.lang.String uripath)
Returns a ServletContext object that corresponds to a
specified URL on the server.
java.lang.String getInitParameter(java.lang.String name)
Returns a String containing the value of the named
context-wide initialization parameter, or null if the parameter
does not exist.
java.util.Enumeration getInitParameterNames()
Returns the names of the context's initialization
parameters as an Enumeration of String objects, or an empty
Enumeration if the context has no initialization parameters.
int getMajorVersion()
Returns the major version of the Java Servlet API that this
servlet container supports.
java.lang.String getMimeType(java.lang.String file)
Returns the MIME type of the specified file, or null if
the MIME type is not known.
int getMinorVersion()
Returns the minor version of the Servlet API that this
servlet container supports.
RequestDispatcher getNamedDispatcher(java.lang.String name)
Returns a RequestDispatcher object that acts as a
wrapper for the named servlet.
java.util.Enumeration getServlets()
Deprecated. As of Java Servlet API 2.0, with no
replacement.
Objek out
Objek ini merupakan cetakan dari class javax.servlet.jsp.JspWriter. Berikut ini adalah properti-
properti yang dimilikinya :
Field Summary
protected boolean autoFlush
Method Summary
abstract void clear()
Clear the contents of the buffer.
abstract void clearBuffer()
Clears the current contents of the buffer.
abstract void close()
Close the stream, flushing it first
abstract void flush()
Flush the stream.
int getBufferSize()
This method returns the size of the buffer used by the JspWriter.
abstract int getRemaining()
This method returns the number of unused bytes in the buffer.
boolean isAutoFlush()
This method indicates whether the JspWriter is autoFlushing.
abstract void newLine()
Write a line separator.
abstract void print(boolean b)
Print a boolean value.
abstract void print(char c)
Print a character.
abstract void print(char[] s)
Print an array of characters.
abstract void print(double d)
Print a double-precision floating-point number.
abstract void print(float f)
Print a floating-point number.
abstract void print(int i)
Print an integer.
abstract void print(long l)
Print a long integer.
abstract void print(java.lang.Object obj)
Print an object.
abstract void print(java.lang.String s)
Print a string.
abstract void println()
Objek config
Objek ini di dibuat dari class javax.servlet.ServletConfig. Method-method yang dimilikinya
adalah :
Method Summary
java.lang.String getInitParameter(java.lang.String name)
Returns a String containing the value of the named
initialization parameter, or null if the parameter does not exist.
java.util.Enumeration getInitParameterNames()
Returns the names of the servlet's initialization parameters
as an Enumeration of String objects, or an empty
Enumeration if the servlet has no initialization parameters.
ServletContext getServletContext()
Returns a reference to the ServletContext in which the
caller is executing.
java.lang.String getServletName()
Returns the name of this servlet instance.
Objek page
Objek page dibuat dari class java.lang.Object.
Objek exception
Objek ini dibuat dari class java.langThrowable.
Cacatan Penulis :
Penulis adalah pemula dalam mempelajari Java, jadi mohon masukkannya bagi pembaca yang
menemukan kesalahan konsep atau asumsi yang digunakan penulis.