You are on page 1of 5

1. After hitting submit button, a JSP page processes a database transaction.

You have
accidentally closed the browser window. Will the database transaction continue or will
get over?
2. What is the difference between http GET and POST methods ?
3. There are 10 servlets in your web application, and they are frequently used (sticky
Servlet). How will you optimize their loading?
4. How will you communicate across Servlets? (or, how will you achieve Inter
Servlet communication?)
5. Hope, you know the difference between RequestDispatcher.forward() and
RequestDispatcher.sendRedirect(). So, which one is desirable to use?
6. What is the class path hierarchy for a Servlet?
7. You can’t read files (located out of tomcat directory) from JSP and Servlets for
security purpose. But, how will you access those files from JSP or Servlets, in case if you
need them?

1. How differ servlets from its peer technology?


ans: It will be clear if know the peer technology. If the technology is CGI , it create a
process for each client request but servlet technology just creates a thread.
2. What is difference between servlet and ASP?
3. Have you used threads in Servelet
4. What is the difference between Generic servlet and HTTPServlet?
5. How do to prevent user by viewing secured page by clicking back button when session
expired
6. How do we prevent user to read secured page.. after logout
7. What is default Session time out in the servers like Tomcat, Weblogic, JBoss,..etc?
8. What is difault http method in http servlet?
9. How can a servlet automatically updated by its data without refreshing? take one
example of sensex site, the corresponding data are shown in a scrolling manner. How
they can automatically be refreshed after some time. without refreshing the page.
10. What is send redirect method? and when it is used?
11. In servlets, what is the use of sendredirect(), include( ), forward()? In applecation
level at what scnario they will be used
12. How to get initialization time (init () method)values in servlet?
13. How to get value from init() method in servlet? How to get initializaion time values
from init() in servlet?
14. How we can check in particular page the session will be alive or not?
15. In which conditions we have to use the ServletContext
16. Suppose in web.xml file we are given 30 and in the servlet program we are given
setSessionInActiveInterval(40). When that session will be terminated? After 30 sec or 40
sec?
session will be terminated depending upon the later updation means it depend upon the
xml file and
17. How much amount of information will be stored within a session
18. What are the JSP atrributes?
19. How to encode textbox in servlet so we find complete column information from the
database
20. Types of Servlets?

What is a Singleton class. How do you write it ?


Article Number: 23084 | Rating: Unrated | Last Updated: Sun, Dec 27, 2009 at 1:53 PM
SingleTon class : is a special class which provides only one instance.
Ex:Container Developers are using this class.

Code is like this:

//This is Single ton class


public class SingleTon
{
private static SingleTon ton = null;
public static SingleTon getName()
{
if(ton == null)
{
ton = new SingleTon();
return ton;
}
}

//tnis outside class where you can call getName() method but you will get same Instance

public class TonInsatnce


{
public static void main(String args[])
{
Object object = SingleTon.getName();
}
}

Difference between MVC1 and MVC 2


ANS
Hi,MVC is a design pattern. It contains two models. MVC Model 1, MVC Model 2.Struts
framework implements MVC Design Pattern. Struts can implement Model 1 and Model
2. Model 2 most properly describes the application of MVC in a Web-Application
context.Following are the important feature of MVC1 architecture: (1) HTML or JSP
files are used to code the presentation. JSP files use java beans to retrieve data if required.
(2)MVC1 architecture is page-centric design all the business and processing logic means
any JSP page can either present in the JSP or may be called directly from the JSP page.
(3)Data access is usually done using Custom tag or through java bean call.Therefore we
can say that in MVC1 there is tight coupling between page and model.Following are the
important feature of MVC2 architecture(1)This architecture removes the page-centric
property of MVC1 architecture by separating Presentation, Control logic and Application
state(2)In MVC2 architecture there is one Controller which receive all request for the
application and is responsible for taking appropriate action in response to each request.
Second one is Model which is represented by JavaBeans, business object, and database.
Third one is View or is JSP page it takes the information provided by Controller and
Module and presents it to user.Raj

How do to prevent user by viewing


secured page by clicking back button
when session expired..:)
Article Number: 23162 | Rating: Unrated | Last Updated: Sun, Dec 27, 2009 at 2:29 PM

You will need to set the appropriate HTTP header attributes to prevent the dynamic
content output by the JSP page from being cached by the browser. Just execute the
following scriptlet at the beginning of your JSP pages to prevent them from being cached
at the browser. You need both the statements to take care of some of the older browser
versions.

<%

response.setHeader("Cache-Control","no-store"); //HTTP 1.1

response.setHeader("Pragma","no-cache"); //HTTP 1.0

response.setDateHeader ("Expires", 0); //prevents caching at the proxy server


%>

ow can a servlet automatically updated


by its data without refreshing?
Article Number: 23166 | Rating: Unrated | Last Updated: Sun, Dec 27, 2009 at 2:31 PM
Question :
How can a servlet automatically updated by its data without refreshing?
take one example of one sensex site. the corresponding data are shown in a scrolling
manner. how they can automatically be refreshed after some time. without
refreshing the page.
Answers:

If i am thinking in the right direction u want to only update a portion of the page
not the entire page.

The entire page mechanism is easy using javascript autorefresh

setTimeout("window.location.reload()",1000)

Enter this script in the head portion of the html page in script tags

But the best solution is to use AJAX. If you are using gmail or meebo u would
understand what it is all about.

cheers
Re: How we can check in particular page the session will be alive or not Answer
#3
when we create session , we write
HttpSession session= res.getSessionn(true);
this checks whether there is a session bind on associated
request.if yes then it returns reference to session
object,otherwise create a session for associated request.

but if we want check that session is alive or not then we


write
HttpSession session= res.getSessionn(false);
this checks whether there is a session bind on associated
request.if yes then it returns reference to session
object,otherwise it returns null reference.

You might also like