We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14
Unit 6
Servlet Interface Methods
Method Description Syntax Arguments Return Value init() Initializes the void init(ServletConfig config) ServletConfig config - None servlet. Servlet configuration. destroy() Cleans up resources void destroy() None None before removal. service() Handles requests void service(ServletRequest req: Request object; None and generates req, ServletResponse res) res: Response object. responses. getServletConfig() Retrieves the servlet ServletConfig None ServletConfig configuration object. getServletConfig() object getServletInfo() Provides metadata String getServletInfo() None Metadata as String about the servlet.
ServletContext Interface Methods
Method Description Syntax Arguments Return Value getAttribute() Retrieves an object Object String name - Object stored in the context. getAttribute(String Attribute name. name) getInitParameter() Retrieves a context String String name - Parameter as initialization getInitParameter(Str Parameter name. String parameter. ing name) getInitParameterNames() Returns all Enumeration<String None Enumeration<Stri initialization > ng> parameter names. getInitParameterNa mes() setAttribute() Stores an object in void String name: None the context. setAttribute(String Attribute name, name, Object value) Object value. removeAttribute() Removes an attribute void String name - None from the context. removeAttribute(Stri Attribute name. ng name) ServletConfig Interface Methods Method Description Syntax Arguments Return Value getInitParameter() Retrieves a servlet String String name Parameter as String initialization getInitParameter(String - Parameter parameter. name) name. getInitParameterNames() Returns all Enumeration<String> None Enumeration<String> initialization getInitParameterNames() parameter names. getServletContext() Retrieves the ServletContext None ServletContext object ServletContext getServletContext() object. getServletName() Retrieves the name String getServletName() None Servlet name as of the servlet. String
ServletRequest Interface Methods
Method Description Syntax Arguments Return Value getAttribute() Retrieves an Object getAttribute(String String name - Object attribute from the name) Attribute name. request. getAttributeNames() Returns all Enumeration<String> None Enumeration<String> attribute names in getAttributeNames() the request. getParameter() Retrieves a String getParameter(String String name - Parameter as String parameter value. name) Parameter name. getParameterNames( Returns all Enumeration<String> None Enumeration<String> ) parameter names getParameterNames() in the request. getParameterValues() Retrieves all String[] String name - Array of values as values of a getParameterValues(String Parameter String[] parameter. name) name.
ServletResponse Interface Methods
Method Description Syntax Arguments Return Value getLocale() Retrieves the Locale getLocale() None Locale object response locale. getWriter() Retrieves the writer PrintWriter getWriter() None PrintWriter object for the response. reset() Resets the response void reset() None None buffer. setLocale() Sets the response void setLocale(Locale loc) Locale loc - Locale None locale. object. setContentType() Sets the MIME type void setContentType(String String type - MIME None of the response. type) type. GenericServlet Class Methods Method Description Syntax Arguments Return Value init() Initializes the void init(ServletConfig ServletConfig None servlet. config) config - Servlet configuration. service() Handles client void req: Request None requests. service(ServletRequest object; res: req, ServletResponse res) Response object. destroy() Cleans up resources. void destroy() None None getServletConfig() Retrieves servlet ServletConfig None ServletConfig object configuration. getServletConfig() getServletInfo() Provides metadata String getServletInfo() None Metadata as String about the servlet. getInitParameter() Retrieves an String String name - Parameter as String initialization getInitParameter(String Parameter parameter. name) name. getInitParameterNames() Returns all init Enumeration<String> None Enumeration<String> parameter names. getInitParameterNames() getServletName() Retrieves the String getServletName() None Servlet name as servlet name. String log() Logs a message to void log(String message) String message - None the servlet log. Message to log.
HttpServlet Class Methods
Method Description Syntax Arguments Return Value doGet() Handles HTTP GET void doGet(HttpServletRequest req, req, res - Request and None requests. HttpServletResponse res) Response objects. doPost() Handles HTTP POST void doPost(HttpServletRequest req, res - Request and None requests. req, HttpServletResponse res) Response objects. doPut() Handles HTTP PUT void doPut(HttpServletRequest req, req, res - Request and None requests. HttpServletResponse res) Response objects. doDelete() Handles HTTP DELETE void doDelete(HttpServletRequest req, res - Request and None requests. req, HttpServletResponse res) Response objects. doHead() Handles HTTP HEAD void doHead(HttpServletRequest req, res - Request and None requests. req, HttpServletResponse res) Response objects. doOptions() Handles HTTP OPTIONS void doOptions(HttpServletRequest req, res - Request and None requests. req, HttpServletResponse res) Response objects. doTrace() Handles HTTP TRACE void doTrace(HttpServletRequest req, res - Request and None requests. req, HttpServletResponse res) Response objects. getLastModified() Returns last modification long HttpServletRequest Time time of resource. getLastModified(HttpServletReques req - Request object. as t req) long HttpServletRequest Interface Methods Method Description Syntax Arguments Return Value getCookies() Retrieves all cookies in the Cookie[] getCookies() None Array of Cookie request. objects getQueryString() Retrieves the query string. String getQueryString() None Query string as String. getSession() Retrieves the current session HttpSession None HttpSession object or creates one. getSession()
HttpServletResponse Interface Methods
Method Description Syntax Arguments Return Value addCookie() Adds a cookie to the void addCookie(Cookie Cookie cookie - Cookie None response. cookie) object. sendRedirect() Redirects the client void String location - URL to None to another URL. sendRedirect(String redirect. location) getStatus() Retrieves the HTTP int getStatus() None HTTP status status code. code as int. getHeader() Retrieves a specific String getHeader(String String name - Header Header value header. name) name. as String. getHeaderNames() Retrieves all header Collection<String> None Collection of names. getHeaderNames() header names setStatus() Sets the HTTP status void setStatus(int sc) int sc - HTTP status None code. code. sendError() Sends an error void sendError(int sc, int sc: Status code, None response to the String msg) String msg: Error client. message.
Cookie Class Methods
Method Description Syntax Arguments Return Value setMaxAge() Sets the maximum age of void setMaxAge(int int expiry - Lifetime in None the cookie. expiry) seconds. getName() Retrieves the cookie name. String getName() None Name as String. getValue() Retrieves the cookie value. String getValue() None Value as String. setName() Sets the cookie name. void setName(String String name - Cookie None name) name. setValue() Sets the cookie value. void setValue(String String value - Cookie None value) value. HttpSession Interface Methods Method Description Syntax Arguments Return Value getAttribute() Retrieves an Object getAttribute(String String name - Object attribute from the name) Attribute name. session. getAttributeNames() Retrieves all Enumeration<String> None Enumeration<S attribute names. getAttributeNames() tring> getCreationTime() Retrieves session long getCreationTime() None Creation time creation time. as long. getId() Retrieves the String getId() None Session ID as session ID. String. getLastAccessedTime( Retrieves last long getLastAccessedTime() None Time as long. ) access time of session.
HttpSessionEvent Class Methods
Method Description Syntax Arguments Return Value sessionCreated() Triggered when void HttpSessionEvent None a session is sessionCreated(HttpSessionEvent event - Session created. event) event. sessionDestroyed() Triggered when void HttpSessionEvent None a session is sessionDestroyed(HttpSessionEvent event - Session destroyed. event) event.
HttpSessionBindingEvent Class Methods
Method Description Syntax Arguments Return Value getName() Retrieves the name of the String getName() None Name as String. bound attribute. getValue() Retrieves the value of the Object getValue() None Value as Object. bound attribute. getSession() Retrieves the session HttpSession getSession() None HttpSession associated with the event. object. Unit 5
Connection Interface Methods
Method Description Syntax Arguments Return Value createStatement() Creates a Statement object Statement None Statement object for sending SQL queries. createStatement() prepareStatement() Creates a PreparedStatement String sql - SQL PreparedStatement PreparedStatement object prepareStatement(String query string. object for parameterized sql) queries. close() Closes the connection. void close() None None commit() Commits the current void commit() None None transaction. rollback() Rolls back the current void rollback() None None transaction. getMetaData() Retrieves metadata about DatabaseMetaData None DatabaseMetaData the database. getMetaData() object setAutoCommit() Sets the autocommit void boolean None mode for the connection. setAutoCommit(boolean autoCommit - autoCommit) Autocommit flag.
Driver Interface Methods
Method Description Syntax Arguments Return Value connect() Attempts to establish a Connection connect(String String url: Database Connection object connection to a url, Properties info) URL, Properties info: database. Properties object. acceptsURL() Checks if the driver can boolean acceptsURL(String String url - Database boolean handle a given URL. url) URL. getPropertyInfo() Retrieves information DriverPropertyInfo[] String url: Database Array of about the possible getPropertyInfo(String url, URL, Properties info: DriverPropertyInfo properties. Properties info) Properties object. getMajorVersion() Retrieves the major int getMajorVersion() None Driver's major version of the driver. version getMinorVersion() Retrieves the minor int getMinorVersion() None Driver's minor version of the driver. version jdbcCompliant() Checks if the driver is boolean jdbcCompliant() None boolean JDBC compliant. Statement Interface Methods Method Description Syntax Arguments Return Value executeQuery() Executes an SQL SELECT ResultSet String sql - SQL ResultSet object query and retrieves executeQuery(String sql) query string. results. executeUpdate() Executes an SQL INSERT, int executeUpdate(String String sql - SQL Number of rows UPDATE, or DELETE sql) query string. affected query. execute() Executes any SQL query boolean execute(String sql) String sql - SQL boolean (SELECT or non-SELECT). query string. indicating success addBatch() Adds an SQL query to the void addBatch(String sql) String sql - SQL None batch. query string. clearBatch() Clears all queries in the void clearBatch() None None batch. close() Closes the statement void close() None None object.
ResultSet Interface Methods
Method Description Syntax Arguments Return Value next() Moves to the next row in boolean next() None boolean the result set. getString() Retrieves a column value as String getString(int int columnIndex - Column Column value as a string. columnIndex) index (1-based). String getInt() Retrieves a column value as int getInt(int int columnIndex - Column Column value as an integer. columnIndex) index (1-based). int close() Closes the result set. void close() None None getMetaData( Retrieves metadata about ResultSetMetaData None ResultSetMetaData ) the result set. getMetaData() object absolute() Moves the cursor to a boolean absolute(int int row - Row number. boolean specific row. row)
DriverManager Class Methods
Method Description Syntax Arguments Return Value getConnection() Establishes a connection Connection String url - Database Connection to the database. getConnection(String url) URL. object registerDriver() Registers a JDBC driver. void registerDriver(Driver Driver driver - JDBC None driver) driver. deregisterDriver() Deregisters a JDBC driver. void Driver driver - JDBC None deregisterDriver(Driver driver. driver) getDrivers() Retrieves an enumeration Enumeration<Driver> None Enumeration of of registered drivers. getDrivers() Driver setLogWriter() Sets the log writer for void PrintWriter out - Log None tracing. setLogWriter(PrintWriter writer. out) getLogWriter() Retrieves the log writer. PrintWriter getLogWriter() None PrintWriter object
Unit 4
InetAddress Class Methods
InetAddress Class Short Description: Represents an Internet Protocol (IP) address. This class provides methods for obtaining and manipulating IP addresses. Constructors: o This class does not have public constructors. Instances are created using factory methods such as getByName(), getLocalHost(), or getByAddress(). Method Description Syntax Parameters Return Value getByName() Retrieves an static InetAddress String host - InetAddress InetAddress by its getByName(String host) Hostname or IP object hostname. address. getLocalHost() Retrieves the local host static InetAddress None InetAddress address. getLocalHost() object getByAddress(byte[] Retrieves an static InetAddress byte[] addr - IP InetAddress addr) InetAddress by its raw getByAddress(byte[] addr) address. object IP address. getAllByName() Retrieves all IP static InetAddress[] String host - Array of addresses for a getAllByName(String host) Hostname. InetAddress hostname. objects equals() Compares this address boolean equals(Object obj) Object obj - boolean to another. Address to compare. getAddress() Retrieves the raw IP byte[] getAddress() None Array of bytes address. getHostAddress() Retrieves the IP String getHostAddress() None IP address as address in textual String form. getHostName() Retrieves the hostname String getHostName() None Hostname as for this IP address. String hashCode() Returns the hash code int hashCode() None Hash code as for this address. int isMulticastAddress() Checks if this is a boolean None boolean multicast address. isMulticastAddress() toString() Returns a string String toString() None Address as representation of the String InetAddress. Socket Class Methods Short Description: Represents a client-side socket that connects to a server socket. It provides methods for sending and receiving data over a network. Constructors: 1. Socket() Creates an unconnected socket. 2. Socket(String host, int port) Creates a socket and connects it to the specified host and port. 3. Socket(InetAddress address, int port) Creates a socket and connects it to the specified IP address and port. 4. Socket(String host, int port, InetAddress localAddr, int localPort) Creates a socket and binds it to a local address and port. 5. Socket(InetAddress address, int port, InetAddress localAddr, int localPort) Creates a socket and binds it to a local IP address and port.
Method Description Syntax Parameters Return Value
connect() Connects this socket to a void SocketAddress None remote server. connect(SocketAddress endpoint - endpoint) Server address. getInetAddress() Retrieves the remote InetAddress None InetAddress address of this socket. getInetAddress() object getPort() Retrieves the remote int getPort() None Port number port. as int getLocalPort() Retrieves the local port. int getLocalPort() None Local port as int getRemoteSocketAddress() Retrieves the remote SocketAddress None SocketAddress socket address. getRemoteSocketAddress() object getInputStream() Retrieves the input InputStream None InputStream stream for this socket. getInputStream() object getOutputStream() Retrieves the output OutputStream None OutputStream stream for this socket. getOutputStream() object close() Closes the socket. void close() None None
ServerSocket Class Methods
Short Description: Represents a server-side socket that waits for incoming connections from client sockets. Constructors: 1. ServerSocket() Creates an unbound server socket. 2. ServerSocket(int port) Creates a server socket bound to the specified port. 3. ServerSocket(int port, int backlog) Creates a server socket bound to the specified port with a queue length for incoming connections. 4. ServerSocket(int port, int backlog, InetAddress bindAddr) Creates a server socket bound to the specified port and address with a queue length.
Method Description Syntax Parameters Return Value
getLocalPort() Retrieves the port this server int getLocalPort() None Port number as socket is listening on. int accept() Listens for a connection to be Socket accept() None Socket object made. setSoTimeout() Sets the timeout for blocking void setSoTimeout(int timeout) int timeout - None accept calls. Timeout in milliseconds. bind() Binds the server socket to a void bind(SocketAddress SocketAddress None specific address. endpoint) endpoint - Address.
URL Class Methods
Short Description: Represents a Uniform Resource Locator (URL), a pointer to a "resource" on the World Wide Web. Constructors: 1. URL(String spec) Creates a URL object from the specified URL string. 2. URL(String protocol, String host, int port, String file) Creates a URL object with the specified protocol, host, port, and file. 3. URL(String protocol, String host, String file) Creates a URL object with the specified protocol, host, and file. 4. URL(URL context, String spec) Creates a URL object from a specified context URL and a string.
Method Description Syntax Parameters Return Value
getPort() Retrieves the port number in int getPort() None Port number as the URL. int getProtocol() Retrieves the protocol of the String getProtocol() None Protocol as URL. String getHost() Retrieves the hostname in the String getHost() None Hostname as URL. String getFile() Retrieves the file path in the String getFile() None File path as URL. String getPath() Retrieves the full path in the String getPath() None Path as String URL. getQuery() Retrieves the query string in the String getQuery() None Query string as URL. String equals() Compares this URL to another. boolean equals(Object obj) Object obj - boolean URL to compare. openConnection() Opens a connection to the URLConnection None URLConnection resource represented by the openConnection() object URL. openStream() Opens an input stream to the InputStream openStream() None InputStream URL. object getContent() Retrieves the content of the Object getContent() None Content as URL. Object URLConnection Short Description: Represents a connection to a URL, providing methods for communication with the resource referred to by the URL. Constructors: This class does not have public constructors. Instances are created by invoking the openConnection() method on a URL object.
DatagramPacket Class Methods
Short Description: Represents a data packet used for connectionless socket communication, such as UDP. Constructors: 1. DatagramPacket(byte[] buf, int length) Creates a datagram packet for receiving data with a specified buffer and length. 2. DatagramPacket(byte[] buf, int offset, int length) Creates a datagram packet for receiving data with a specified buffer, offset, and length. 3. DatagramPacket(byte[] buf, int length, InetAddress address, int port) Creates a datagram packet for sending data to a specified address and port. 4. DatagramPacket(byte[] buf, int offset, int length, InetAddress address, int port) Creates a datagram packet for sending data with specified buffer, offset, length, address, and port.
Method Description Syntax Parameters Return Value
getAddress() Retrieves the address to InetAddress getAddress() None InetAddress which the packet is object sent/received. getData() Retrieves the data buffer of byte[] getData() None Array of bytes the packet. getLength() Retrieves the length of the int getLength() None Length as int data in the packet. getPort() Retrieves the port to which int getPort() None Port as int the packet is sent/received. setData() Sets the data buffer for the void setData(byte[] data) byte[] data - None packet. Data buffer. setLength() Sets the length of the data in void setLength(int length) int length - None the packet. Length of data.
DatagramSocket Class Methods
Short Description: Represents a connectionless socket for sending and receiving datagram packets using UDP. Constructors: 1. DatagramSocket() Creates a datagram socket and binds it to a random port. 2. DatagramSocket(int port) Creates a datagram socket and binds it to the specified port. 3. DatagramSocket(int port, InetAddress laddr) Creates a datagram socket and binds it to the specified local port and address.
Method Description Syntax Parameters Return Value
close() Closes the socket. void close() None None getLocalAddress() Retrieves the local InetAddress getLocalAddress() None InetAddress address of the socket. object getLocalPort() Retrieves the local port int getLocalPort() None Local port as int of the socket. receive() Receives a datagram void receive(DatagramPacket p) DatagramPacket None packet. p - Packet. send() Sends a datagram void send(DatagramPacket p) DatagramPacket None packet. p - Packet. Unit 3
ActionEvent Class Methods
Method Description Syntax Parameters Return Value getActionCommand() Retrieves the command string String getActionCommand() None Command string associated with the event. as String getModifiers() Retrieves the modifier keys int getModifiers() None Modifier keys as pressed during the event. int getWhen() Retrieves the time at which the long getWhen() None Timestamp as event occurred. long
ItemEvent Class Methods
Method Description Syntax Parameters Return Value getItem() Retrieves the affected item Object getItem() None Affected item as in the event. Object getItemSelectable() Retrieves the component ItemSelectable getItemSelectable() None Component as that triggered the event. ItemSelectable getStateChange() Retrieves the change in the int getStateChange() None State change as int item's state.
KeyEvent Class Methods
Method Description Syntax Parameters Return Value getKeyChar() Retrieves the character associated char getKeyChar() None Key character as with the key event. char getKeyCode() Retrieves the integer code for the key int getKeyCode() None Key code as int pressed.
MouseEvent Class Methods
Method Description Syntax Parameters Return Value getButton() Retrieves the mouse button int getButton() None Button code as involved in the event. int getClickCount() Retrieves the number of int getClickCount() None Number of mouse clicks. clicks as int getPoint() Retrieves the point where Point getPoint() None Point as Point the event occurred. object getLocationOnScreen( Retrieves the location of the Point getLocationOnScreen() None Screen location ) event on the screen. as Point getX() Retrieves the X coordinate of int getX() None X coordinate as the event. int getY() Retrieves the Y coordinate of int getY() None Y coordinate as the event. int
TextEvent Class Methods
Method Description Syntax Parameters Return Value paramString() Returns a string String paramString() None String representation of the event. representation
WindowEvent Class Methods
Method Description Syntax Parameter Return Value s getNewState() Retrieves the new state of int getNewState() None New state as int the window after the event. getOldState() Retrieves the previous int getOldState() None Old state as int state of the window before the event. getOppositeWindow() Retrieves the window that Window getOppositeWindow() None Opposite window as is opposite in the event. Window getWindow() Retrieves the window that Window getWindow() None Triggering window triggered the event. as Window