Posts

Showing posts from December, 2017

javax.servlet.ServletConfig interface detail

Image
ServletConfig is an interface of servlet API. Implementation of which is provided by vendors. An object of type ServletConfig is created by the server for each servlet. This object has following use: 1- It is used by the server to provide Servlet specific initialization parameter to     Servlets.  2- It is used by the server to provide reference of the ServletContext object to the Servlet. 2.2- ServletConfig object is created for the Servlet. 2.3- <init-param> (if define for the Servlet) are read and store in it. 2.4- Reference of ServletContext is saved in it. 3.0- Server call the init() method of Servlet and provide the reference of ServletConfig. Method of javax.servlet.ServletConfig interface: 1- getServletContext():                                     ...

javax.servlet.ServletContext interface detail

Image
ServletContext is an interface of Servlet API. Implementation of it provided by the vendors. An object of type ServletContext is created by the server per application at the time of application deployment. This object has following use: 1- It is used by the server to store application specific initialization parameters. 2- It is used by the Servlet to share information among them self in the form of     attributes. 3- It is used by the Servlet to interact with the server that is it has interface of the server. 1.1- ServletContext object is created by the server for the application. 1.2- <context-param> defined in web.xml are read and stored in ServletContext      object. 1.3- Server provides its own reference to the ServletContext object. 2.0- Servlet read application scope initialization parameters. 2.1- Servlet share information among themselves across requests as attributes. 2.2- Servlets use ServletContext object as...

Initialization Parameters in servlet

Image
Initialization parameter represents variable textual information that is define by application developer in web.xml file and is made available to the Servlets by the web server.  Initialization parameter can be of 2 types: 1- Application specific 2- Servlet specific 1- Application specific:                                       Application specific initialization parameters represent textual information that is to be made available to all the Servlet of the application. <context-param> xml element is used for defining application specific initialization parameter in web.xml. <web-app> <context-param>* <param-name>ParameterName</param-name> <param-value>ParameterValue</param-value> </context-param> ---------...

Login Authentication program (Demonstrate the use RequestDispatcher and its method such as include() and forward() )

Image
Create Table with following field: TableName: USERINFO id                    name                 password 101                 rupendra            a@b.com 102                 rahul                  x@y.com Program save with Name: index.html <html> <head><title>Login Page</title></head> <body> <form method="get" action="loginServlet"> UserId : <input type="text" name="txtUserId"><br> Password : <input ...

RequestDispatcher interface

RequestDispatcher is a interface of Servlet API. Implementation of which provided by vendors. This interface provides methods for including contents of a resource (Such as Servlet/html page etc.) to the response of current Servlet or forward the request to another web resource(Such as Servlet/html page etc.). Methods: 1- getRequestDispatcher():                                                Method of ServletRequest interface is used to obtain a RequestDispatcher object. public RequestDispatcher getRequestDispatcher(String URL of Resource); RequestDispatcher interface provides include() and forward() method for including contents of a resource and to forward the request to another response respectively. I) include():      ...

Program to access word and Excel document (Demonstrate the use of ServletRequest and ServletResponse methods such as setContentType())

Program save with Name: index.html <html> <head><title>Downloading Program</title></head> <body> <a href="wordServlet">Ms-Word-Document</a><br> <a href="excelServlet">Ms-Excel-Document</a> </body> </html> Program save with Name: WordServlet.java import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class WordServlet extends HttpServlet {           public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException           {                    response.setContentType( "application/msword" );                  ...