The JSP request is an implicit object of type HttpServletRequest i.e. created for each jsp request by the web container. It can be used to get request information such as parameter, header information, remote address, server name, server port, content type, character encoding etc.
It can also be used to set, get and remove attributes from the jsp request scope.
Let's see the simple example of request implicit object where we are printing the name of the user with welcome message.
Example of JSP request implicit object
index.html
welcome.jsp
Output
JSP response implicit object
In JSP, response is an implicit object of type HttpServletResponse. The instance of HttpServletResponse is created by the web container for each jsp request.
It can be used to add or manipulate response such as redirect response to another resource, send error etc.
Let's see the example of response implicit object where we are redirecting the response to the Google.
Example of response implicit object
index.html
welcome.jsp
Output
JSP config implicit object
In JSP, config is an implicit object of type ServletConfig. This object can be used to get initialization parameter for a particular JSP page. The config object is created by the web container for each jsp page.
Generally, it is used to get initialization parameter from the web.xml file.
Example of config implicit object:
index.html
web.xml file
welcome.jsp
Output
JSP application implicit object
In JSP, application is an implicit object of type ServletContext.
The instance of ServletContext is created only once by the web container when application or project is deployed on the server.
This object can be used to get initialization parameter from configuaration file (web.xml). It can also be used to get, set or remove attribute from the application scope.
This initialization parameter can be used by all jsp pages.
Example of application implicit object:
index.html
web.xml file
welcome.jsp
No comments:
Post a Comment