java4all@1986 java. Powered by Blogger.

>> Wednesday, June 15, 2011

Q).What are the uses of ServletRequest Interface?
A).ServletRequest defines an object to provide client request information to a servlet.
The servlet container creates a ServletRequest object and passes it as an argument to the servlet's
service method.

A ServletRequest object provides data including parameter name and values, attributes, and an input stream. Interfaces that extend ServletRequest can provide additional protocol-specific data (for example, HTTP data is provided by HttpServletRequest.

Packages that use ServletRequest :
  * javax.servlet      
  * javax.servlet.http      
  * javax.servlet.jsp

Q).How can a servlet Refresh automatically?
A).We can Refresh Servlet Page by two ways : one through client side and another through Server Push.

Client Side Refresh :
< META HTTP-EQUIV="Refresh" CONTENT="5; URL=/servlet/MyServlet/">


Server Side Refresh :
response.setHeader("Refresh",5);

This will update the browser after every 5 seconds.

Q).How does a servlet handles multiple requests at a time?
A).Servlets are under the control of web container. When a request comes for the servlet,
the web container find out the correct servelt based on the URL, and create a separeate thread for each request.
In this way each request is processed by the different thread simultaneously.

Q).What is difference between Context Init parameter and servlet init parameter?
A).Context init parameter is accessible through out the web application and declared outside the <servlet>...</servlet>
element tag in the deployment descriptor(DD) . Servlet init parameters are declared inside the <servlet>...</servlet>
element and only accessible only to the that specific servlet. You can access the context init parameters using the getServletContext() method and Servlet init parameters using the getServletConfig() method.

Declaring the Servlet init parameter in DD :

<servlet> 
   <servlet-name>My Page</servlet-name>
   <sevlet-class>/mypage</servlet-class> 
   <init-param> 
      <param-name>name</param-name>    //it will be applicable to only one single servlet
      <param-value>pream</param-value) </init-param>
</servlet>

Declaring the Context init parameter in DD :

<context-param> 
<param-name>webmaster</param-name> 
<param-value>apache</param-value>   //it will be applicable to all servlets in an web-application
</context-param>

Q).What meant bt URL encoding and URL decoding?
A).Some characters are not valid in URLs like & can't be placed in a URL query string without changing the meaning of that query string.

These problems can be be fixed by 'escaping' them. This process involves scanning the text for those characters, and replacing them
with a special character-code that browsers can interpret as the correct symbol, without actually using that symbol in your URL.

For example, the escaped character code for '=' is '%3d'.

Q).When a session object is added or removed to session which event will be notified?
A).When an object is added or removed from a session, the container checks the interfaces implemented by the object.
If the object implements the HttpSessionBindingListener, the container calls the matching notification method.
If session is added then sessionCreated() method, and if session is removed then sessionDestroyed() method will be callled automatically by the web container.


0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP