Você está na página 1de 36

Servlet 1.

What is a servlet? Servlets are modules that extend request/response-oriented servers,such as Java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a companys order database. Servlets are to servers what applets are to browsers. Unlike applets, however, servlets have no graphical user interface. Whats the advantages using servlets over using CGI? Servlets provide a way to generate dynamic documents that is both easier to write and faster to run. Servlets also address the problem of doing server-side programming with platform-specific APIs: they are developed with the Java Servlet API, a standard Java extension. What are the general advantages and selling points of Servlets? A servlet can handle multiple requests concurrently, and synchronize requests. This allows servlets to support systems such as online real-time conferencing. Servlets can forward requests to other servers and servlets. Thus servlets can be used to balance load among several servers that mirror the same content, and to partition a single logical service over several servers, according to task type or organizational boundaries. Which package provides interfaces and classes for writing servlets? javax Whats the Servlet Interface? The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or, more commonly, by extending a class that implements it such as HttpServlet.Servlets > Generic Servlet > HttpServlet > MyServlet. The Servlet interface declares, but does not implement, methods that manage the servlet and its communications with clients. Servlet writers provide some or all of these methods when developing a servlet. When a servlet accepts a call from a client, it receives two objects. What are they? ServletRequest (which encapsulates the communication from the client to the server) and ServletResponse (which encapsulates the communication from the servlet back to the client). ServletRequest and ServletResponse are interfaces defined inside javax.servlet package. What information does ServletRequest allow access to? Information such as the names of the parameters passed in by the client, the protocol (scheme) being used by the client, and the names of the remote host that made the request and the server that received it. Also the input stream, as ServletInputStream.Servlets use the input stream to get data from clients that use application protocols such as the HTTP POST and GET methods. What type of constraints can ServletResponse interface set on the client? It can set the content length and MIME type of the reply. It also provides an output stream, ServletOutputStream and a Writer through which the servlet can send the reply data. Explain servlet lifecycle? Each servlet has the same life cycle: first, the server loads and initializes the servlet (init()), then the servlet handles zero or more client requests (service()), after that the server removes the servlet (destroy()). Worth noting that the last step on some servers is done when they shut down. How does HTTP Servlet handle client requests? An HTTP Servlet handles client requests through its service method. The service method supports

2.

3.

4. 5.

6.

7.

8.

9.

10.

standard HTTP client requests by dispatching each request to a method designed to handle that request.

What is the servlet? Servlet is a script, which resides and executes on server side, to create dynamic HTML. In servlet programming we will use java language. A servlet can handle multiple requests concurrently What is the architechture of servlet package? Servlet Interface is the central abstraction. All servlets implements this Servlet Interface either directly or indirectly (may implement or extend Servlet Interfaces sub classes or sub interfaces) Servlet | Generic Servlet | HttpServlet ( Class ) we will extend this class to handle GET / PUT HTTP requests | MyServlet What is the difference between HttpServlet and GenericServlet? A GenericServlet has a service() method to handle requests.HttpServlet extends GenericServlet added new methods doGet() doPost() doHead() doPut() doOptions() doDelete() doTrace() methods Both these classes are abstract. Whats the difference between servlets and applets? Servlets executes on Servers. Applets executes on browser. Unlike applets, however, servlets have no graphical user interface. What are the uses of Servlets? A servlet can handle multiple requests concurrently, and can synchronize requests. Servlets can forward requests to other servers and servlets. Thus servlets can be used to balance load among several servers. When doGET() method will going to execute? When we specified method=GET in HTML Example : < form name='SSS' method='GET'> When doPOST() method will going to execute? When we specified method=POST in HTML < form name='SSS' method='POST' >

What is the difference between Difference between doGet() and doPost()? GET Method : Using get method we can able to pass 2K data from HTML All data we are passing to Server will be displayed in URL (request string). POST Method : In this method we does not have any size limitation. All data passed to server will be hidden, User cannot able to see this info on the browser. What is the servlet life cycle? When first request came in for the servlet , Server will invoke init() method of the servlet. There after if any user request the servlet program, Server will directly executes the service() method. When Server want to remove the servlet from pool, then it will execute the destroy() method Which code line must be set before any of the lines that use the PrintWriter? setContentType() method must be set. Which protocol will be used by browser and servlet to communicate? HTTP In how many ways we can track the sessions? Method 1) By URL rewriting Method 2) Using Session object Getting Session form HttpServletRequest object HttpSession session = request.getSession(true); Get a Value from the session session.getValue(session.getId()); Adding values to session cart = new Cart(); session.putValue(session.getId(), cart); At the end of the session, we can inactivate the session by using the following command session.invalidate(); Method 3) Using cookies Method 4) Using hidden fields How Can You invoke other web resources (or other servelt / jsp ) ? Servelt can invoke other Web resources in two ways: indirect and direct. Indirect Way : Servlet will return the resultant HTML to the browser which will point to another Servlet (Web resource) Direct Way : We can call another Web resource (Servelt / Jsp) from Servelt program itself, by using RequestDispatcher object.

You can get this object using getRequestDispatcher(URL) method. You can get this object from either a request or a Context. Example : RequestDispatcher dispatcher = request.getRequestDispatcher(/jspsample.jsp); if (dispatcher != null) dispatcher.forward(request, response); } How Can you include other Resources in the Response? Using include method of a RequestDispatcher object. Included WebComponent (Servlet / Jsp) cannot set headers or call any method (for example, setCookie) that affects the headers of the response. Example : RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(/banner); &nbspif (dispatcher != null) &nbspdispatcher.include(request, response); } What is the difference between the getRequestDispatcher(String path) ServletRequest interface and ServletContext interface? The getRequestDispatcher(String path) method of ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a / it is interpreted as relative to the current context root. The getRequestDispatcher(String path) method of ServletContext interface cannot accepts relative paths. All path must sart with a / and are interpreted as relative to curent context root. If the resource is not available, or if the server has not implemented a RequestDispatcher object for that type of resource, getRequestDispatcher will return null. Your servlet should be prepared to deal with this condition. What is the use of ServletContext? Using ServletContext, We can access data from its environment. Servlet context is common to all Servlets so all Servlets share the information through ServeltContext. Is there any way to generate PDFS dynamically in servlets? We need to use iText. A open source library for java. Please refer sourceforge site for sample servlet examples. What is the difference between using getSession(true) and getSession(false) methods? getSession(true) - This method will check whether already a session is existing for the user. If a session is existing, it will return that session object, Otherwise it will create new session object and return taht object. getSession(false) - This method will check existence of session. If session exists, then it returns the reference of that session object, if not, this methods will return null.

Explain the life cycle methods of a Servlet. A: The javax.servlet.Servlet interface defines the three methods known as lifecycle method. public void init(ServletConfig config) throws ServletException public void service( ServletRequest req, ServletResponse res) throws ServletException, IOException public void destroy() First the servlet is constructed, then initialized wih the init() method. Any request from client are handled initially by the service() method before delegating to the doXxx() methods in the case of HttpServlet. The servlet is removed from service, destroyed with the destroy() methid, then garbaged collected and finalized.
TOP

Q:What is the difference between the getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface? A: The getRequestDispatcher(String path) method of javax.servlet.ServletRequest interface accepts parameter the path to the resource to be included or forwarded to, which can be relative to the request of the calling servlet. If the path begins with a "/" it is interpreted as relative to the current context root. The getRequestDispatcher(String path) method of javax.servlet.ServletContext interface cannot accepts relative paths. All path must sart with a "/" and are interpreted as relative to curent context root.
TOP

Q:Explain the directory structure of a web application. A: The directory structure of a web application consists of two parts. A private directory called WEB-INF A public resource directory which contains public resource folder. WEB-INF folder consists of 1. web.xml 2. classes directory 3. lib directory
TOP

Q:What are the common mechanisms used for session tracking? A: Cookies SSL sessions URL- rewriting
TOP

Q:Explain ServletContext. A: ServletContext interface is a window for a servlet to view it's environment. A servlet can use this interface to get information such as initialization parameters for the web applicationor servlet container's version. Every web application has one and only one ServletContext and is accessible to all active resource of that

application.
TOP

Q:What is preinitialization of a servlet? A: A container doesnot initialize the servlets ass soon as it starts up, it initializes a servlet when it receives a request for that servlet first time. This is called lazy loading. The servlet specification defines the <load-on-startup> element, which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up. The process of loading a servlet before any request comes in is called preloading or preinitializing a servlet. TOP [ Received from Amit Bhoir ] Q:What is the difference between Difference between doGet() and doPost()? A: A doGet() method is limited with 2k of data to be sent, and doPost() method doesn't have this limitation. A request string for doGet() looks like the following: http://www.allapplabs.com/svt1?p1=v1&p2=v2&...&pN=vN doPost() method call doesn't need a long text tail after a servlet name in a request. All parameters are stored in a request itself, not in a request string, and it's impossible to guess the data transmitted to a servlet only looking at a request string. TOP [ Received from Amit Bhoir ] Q:What is the difference between HttpServlet and GenericServlet? A: A GenericServlet has a service() method aimed to handle requests. HttpServlet extends GenericServlet and adds support for doGet(), doPost(), doHead() methods (HTTP 1.0) plus doPut(), doOptions(), doDelete(), doTrace() methods (HTTP 1.1). Both these classes are abstract. TOP [ Received from Amit Bhoir ] Q:What is the difference between ServletContext and ServletConfig? A: ServletContext: Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file.The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized ServletConfig: The object created after a servlet is instantiated and its default constructor is read. It is created to pass initialization information to the servlet.

JSP Internal Objects


Name the internal objects of JSP? Latest Answer: There are 8 implicit Objects are there ......There are 1.Request2.Response3.Session4.Config5.out6.application7.page8.page context ...
Read Answers (2) | Asked by : sejal k Answer Question Subscribe

Session and Cookie


What is the different between session and cookies? Where is the session information stored? In RAM of the Client or Disk of the Client or it is stored on the server? Latest Answer: Session is stored on Server whereas cookie is on client side....amount of data in session is not limited i.e can have size of data equal to RAM size whereas cookie can take limited amount of data....Cookie can be manually dissabled by the client ...
Read Answers (1) | Asked by : jpjese Answer Question Subscribe

Controller Functions
Describe the functions of Controller? Latest Answer: Controller as the name specifies is a part of the application server that controlles the whole application.In MVC(if you are aware of model,view,controller) the maintasks of the controller are:1> Take the user inputs from the request and understand what ...
Read Answers (1) | Asked by : desh12345 Answer Question Subscribe

_jspService() Method
Why do we use underscore(_) symbol only with jspService() method? Latest Answer: Any methods are not be overriden by end users are typically written starting with '-'. _jspService method is not also be overriden by end users.Container invoke this method for each request, passing the request and response object. ...
Read Answers (5) | Asked by : kirankumarg Answer Question Subscribe

Forward & include methods


what are forward & include methods? Why these are used? Latest Answer: Both forward() and include() are concrete methods of the RequestDispatcher class in the Servlet context. forward() - this method is used to show a different resource in place of the servlet originally requested. This resource may be a jsp, a servlet etc. ...
Read Answers (1) | Asked by : RajeshKumar.Guru Answer Question Subscribe

Difference Between Web Container and Web Server


What is the Difference Between Web Container and Web Server?(Asked in Polaris Interview , held on April 11, Chennai) Latest Answer: The Webserver: Just Receive the request from the client and forward to Webcontainer, and do the Response vice versa.Web Container: Creates HTTP Request and

Response for the Servlet, calls the appropriate servlet service method (doGet or doPost) to service ...
Read Answers (1) | Asked by : khadarzone Answer Question Subscribe

Servlet container
what is difference between servlet container and servlet config? Latest Answer: servlet container is part of web server which provides run time environment for servlets i.e it manages the entaire life cycle for the servlets like it creates instance,initialization,processing and destroying it. ...
Read Answers (2) | Asked by : gopalraop Answer Question Subscribe

What are the necessary conditions to override the init() in servlets?


For overriding init()method any rules are there Latest Answer: There are no necessary conditions to override this particular method. In case you are overridding init(ServletConfig config), then make sure to call super.init(config). ...
Read Answers (3) | Asked by : pvpadma.mca Answer Question Subscribe

What is Custom Servlet?


Latest Answer: Custom Servlet is user defined servlet which extends HttpServlet class. ... Read Answers (1) | Asked by : prasad Answer Question Subscribe

JSP server process


Explain the server process how will server identifies that and response to corresponding servlet and how it sends to that response to correct user ? Latest Answer: After we request for a jsp. There is a servlet called pagecompilor , which first parses the .jsp page to .java page.then compiles that .java page and produces .class page.EX.if we have mypage.jsp firse myPage-jsp.javathen myPage_jsp.classthen the ...

Servlets Questions
1)What is web.xml?2)what is the filter?3)How to we create a new JSTL class?4)When we are developing the project which collections mostly used?5)Difference between reqeust.getAttribute,and request.getParameter? Latest Answer: 1)What is web.xml?web.xml is nothing but a deployment descriptor. It describes a web applicants deployment settings.2)what is the filter?It is an Pluggable web componenet device it allow us to implement or add pre processing or post processing logic ...
Read Answers (1) | Asked by : Ramu Answer Question Subscribe

What is the use of Service() in servlets? How is that method invoked?


Latest Answer: Service() method is used to handle requests and it is invoked by the

ServletContainer. ...

Read Answers (5) | Asked by : raj Answer Question Subscribe

What is the difference between doGet methods,doGet()and service() used in servlet?can we use service()
What is the difference between doGet methods,doGet()and service() used in servlet?can we use service() methods replace of doGet() and doPost()?
Read Answers (7) | Asked by : ajay Answer Question Subscribe

Why do we need to implement 3rd party support for using connection pooling ?
View Question | Asked by : JavaPassion Answer Question Subscribe

What is the modifier for the HttpServlet class service method?


protected.
Latest Answer: HttpServlet class extends the GenericServlet class.So it has two service methods.

(1) public void service(ServletRequest req,ServletResponce res);(2) protected void service(HttpServletRequest req,HttpServletResponce res);Thus the the modifier for ...
Read Answers (6) | Asked by : sujatham Answer Question Subscribe

What is the difference between servlet and servlet container?


Latest Answer: A Servlet is that portion of your J2EE application which handles ur requets and

where the buisness logic is implemented and depending on the request a response object is generated which is sent back to the client.A Servlet container is that portion of ...
Read Answers (7) | Asked by : sujatham Answer Question Subscribe

Describe Servlet Class Hierarchy.


Class java.lang.Object
Latest Answer:

javax.servlet.servlet

->Interface
Answer Question

...
Subscribe

Read Answers (2) | Asked by : sujatham

What are the Characteristics of Servlets?


The characteristics of servlets that have gained them a wide spread acceptance are as follows:1.Servlets are efficient:The initialization code for a servlet is executed only when the servlet is executed
View Question | Asked by : sujatham Answer Question Subscribe

Why and when do we use connection pool management system instead of database?

Latest Answer: Connection Pooling is like u have created a set of connection pools and hav stored

them in some data structure.The benefit which u get by doing this is everytime u get a new request u can use one of the available connections u don need to establish a ...
Read Answers (6) | Asked by : kiranmaye Answer Question Subscribe

What is the need for having HTTPServlet class when we already have GenericServlet class which can handle
What is the need for having HTTPServlet class when we already have GenericServlet class which can handle all type of requests?

How many Request, Response & session instance you can create for N number of uesr request from a. user
How many Request, Response & session instance you can create for N number of uesr request from a. user request from same userb. user request from diffrent user
Read Answers (2) | Asked by : nitin j Answer Question Subscribe

What is the purpose of hidden fields, cookies and session objects?


Latest Answer: The purpose of hidden fields, cookies and session objects is to transfer data

between different pages of an application. ...


Read Answers (3) | Asked by : chandra Answer Question Subscribe

What is difference between Redirect and request dispatch


Latest Answer: Using the redirect method ,we can forward the request to servlet that is either in

the same servlet container or in other container .When we are using request dispatch method ,we can forward the request only to a servlet that is in the current container. ...
Read Answers (1) | Asked by : hemraj Answer Question Subscribe

How to find out the servlet is demon thread


Latest Answer: You can use the following code to determine whether the thread in which your

code is getting executed is daemon or not.if(Thread.currentThread().isDaemon()) { to execute if daemon.} else { ...


Read Answers (1) | Asked by : naresh reddy Answer Question

//logic

Subscribe

How to call the resource that is available in another web server by using response.sendRedirect()?
Latest Answer: Using this method is pretty straight-forward. BUt there is a simple catch: No data

should be committed to the servlet output stream before the redirection occurs.In case data has been committed and then redirection is forced, an IllegalStateException ...
Read Answers (2) | Asked by : rajesh Answer Question Subscribe

What is hot deployment?


Latest Answer: if we made some chage in web.xml and chang reflect in progm wdout server

restrt thn its called hot deployment ...


Read Answers (3) | Asked by : deepti_charolkar Answer Question Subscribe

What is the main purpose of Servlet? Why it is developed in Java?


Latest Answer: Servlet Technology is an implementation of the CGI standard, much better than

that. It allows you to create dynamic web applications as opposed to the static HTML. ...
Read Answers (2) | Asked by : nirupama Answer Question Subscribe

Why SingleThread model is deprecated in Servlets?


Latest Answer: The use of the SingleThreadModel interface guarantees that only one thread at a

time will execute in a given servlet instances service method. It is important to note that this guarantee only applies to each servlet instance, since the container may ...
Read Answers (4) | Asked by : Raviranjan Kumar Sinha Answer Question Subscribe

Explain about Inter-Servlet communication and business reason for using Inter-Servlet communication
Explain about Inter-Servlet communication and business reason for using Inter-Servlet communication
Read Answers (1) | Asked by : Ramesh Answer Question Subscribe

What is the use of super.init (config) in servlets? Why it is required?


Latest Answer: The init(ServletConfig) method is defined in the Servlet interface. It has been

implemented by the GenericServlet class. The implementation of this init method in the GenericServlet just stores the ServletConfig object in some private variable ...
Read Answers (1) | Asked by : jayalakshmic Answer Question Subscribe

What is the difference between mvc and mvc2 architecture?


I m confuse.
Latest Answer: in the mvc 1 all the view model and presention were keept at only one place but

in mvc 2all thse thingshas putted together ...


Read Answers (2) | Asked by : Chandra Kumar Answer Question Subscribe

Which part of the webserver is responsible for initialization of the servlets?


Latest Answer: It is the servlet container that is responsible for initializing and managing the

servlet life cycle. ...


Read Answers (2) | Asked by : Raghavendra Kamat Answer Question Subscribe

What is the difference between Single Thread Model and Multi Thread Model? In which situation we use

What is the difference between Single Thread Model and Multi Thread Model?In which situation we use the Single Threaded Model?
Read Answers (1) | Asked by : madhu Answer Question Subscribe

What is the difference between URL and URI?


Latest Answer: URL-Uniform Resource Locator & URI-Unifrom Resource Identifier. ... Read Answers (1) | Asked by : madhu Answer Question Subscribe

Where session information gets stored in methods like Cookies, URLRewriting etc.
Latest Answer: In cookies, Session information is stored at client side in a folder called cookie, if

the browser is set to cookie disable mode then this approach will not work.In URL rewriting, it is stored within each URL & attached with header. Except then cookies ...
Read Answers (1) | Asked by : krishna Ballabh Answer Question Subscribe

What is the role of synchronization when we making a servlet as singlethreadmodel?


Latest Answer: SingleThreadModel technique works well for low volume sites, it does not scale

well.All requests that will come for the SingleThreadModel resource would be available only for one user at a time. ...
Read Answers (3) | Asked by : guptakcsg Answer Question Subscribe

What are the disadvantage of Cookie as compare to HttpSession Object?


Latest Answer: Cookies can store bit of information only, ie) less than 4kb of information can

stored and 20 cookies per url and 300 users information can store. Every time server set the cookie it has to check whether it got stored or not by accessing the cookie with ...
Read Answers (1) | Asked by : dile_sahoo Answer Question Subscribe

What is the difference between requestDispatcher and namedDispatcher?


Latest Answer: What I found is there is nothing called namedDispatcher. But there is

a method called getNamedDispatcher() in servletcontext which is similar to getRequestDispatcher(). getNamedDispatcher() ...


Read Answers (1) | Asked by : kiran.pathipaka Answer Question Subscribe

Can you pass object references in Non-distributed Technologies?


Latest Answer: Yes. Non-distributed technologies would mean objects in a single JVM. Within a

single JVM, objects are always passed by reference.When it comes to distributed, which means 2 JVMs running either on the same or different machines, objects are passed by ...
Read Answers (1) | Asked by : enjoy Answer Question Subscribe

How many cookies(max) can store a browser?

Latest Answer: 20 cookies for per website and 300 cookies per uniqe user, also they can limit

each cookie's size to 4096 bytes. ...

What is servlet tunneling? when it will be used?.


Latest Answer: The Servlet tunneling can be thought as a way to use an existing road of

communication (HTTP) and create a sub-protocol within it to perform specific tasks. ...
Read Answers (1) | Asked by : gothlururaaja Answer Question Subscribe

Why servlet used as controller in mvc2?plz explain details


Latest Answer: According to MVC2 the purpose of addition of the controller was to just separate

the dynamic part of the application from the static part and for that the dynamic part given the name "view" is handled as JSP's . while the static part as controller ...
Read Answers (6) | Asked by : Prabhakaran Answer Question Subscribe

In MVC1 architecture there is no controller concept then why it is called as MVC architecture?
Latest Answer: There is MVC means Model, View & Controller, There is no MVC1 & MVC2, There is

Model1 & Model2 Architecture ...


Read Answers (5) | Asked by : sarithareddy Answer Question Subscribe

What happens when we call destroy() method in init() method in servlets


Latest Answer: It does not effect, If U call init() inside destory() method.Coz these are life

cycle methods, so container only call these methods....If u written init() inside destor() but destoy() method can not works. ...
Read Answers (9) | Asked by : sarithareddy Answer Question Subscribe

Why GenericServlet is an abstract class ?


Latest Answer: GenericServlet is an abstract class because its upto the user how he wants it to

use thelife-cycle methods of the servlet and also the server needs to make sure that all the life cycle methods of the servlets have to be implemented.So if a class is extending ...
Read Answers (8) | Asked by : Saurabh Tags : Abstract Answer Question Subscribe

What is dynamic content?In real time example?


Latest Answer: See by dynamic content we mean the content which is decided at

runtime.Depending on the request which a user is sending we get a respose which is dependent on the request and it is not fixed.For example when a user enters his user name and password on ...
Read Answers (4) | Asked by : radhika Answer Question Subscribe

How many hits can Apache tomcat take at a time i.e How many requests it accept at a time.
Latest Answer: Apache tomcat testing version can handle only 50 request at a time. ... Read Answers (2) | Asked by : ashu Answer Question Subscribe

Can we put costructor in place of init() method . if yes how it works plz xplain in detail??
Latest Answer: webcontainer create an object for servlet class.for createing an object use the

newInstance() method.this object automaticaly create a defaultconstructor so we can not create parametarised constructior for this object.praveen kumar sakhamudi ...
Read Answers (5) | Asked by : ashish Answer Question Subscribe

What is the difference between doGet() and doPost() methods of a HttpServlet and when to use each one?
What is the difference between doGet() and doPost() methods of a HttpServlet and when to use each one?
Read Answers (11) | Asked by : rs Answer Question Subscribe

When to use session scope1?How session object is managed by the webcontainer?When the session object
When to use session scope1?How session object is managed by the webcontainer?When the session object is created and when it is removed?

What is difference between HttpServlet and GenericServlet. and when to use and why. what is the importance
What is difference between HttpServlet and GenericServlet. and when to use and why. what is the importance of each.
Read Answers (6) | Asked by : Enayat Answer Question Subscribe

What factors effects on selecting a technology. In deatail, A customer came with SRS, how to select
What factors effects on selecting a technology. In deatail, A customer came with SRS, how to select a technology (java,.net,c,c++) to develop a application?
Read Answers (1) | Asked by : Aruna Answer Question Subscribe

Can we declare class level variables in a servlet?


Latest Answer: Yes we can declare class level variable in a servlet but we can also use it in the

class but as we know taht it is not in our hands to make the instaniate a servlet so cannot use that class level variable by instaniating ...
Read Answers (1) | Asked by : Raj

Answer Question

Subscribe

What is serverlet life cycle?


Latest Answer: servlet lifecycle consists of 5 methods but most of the time it concentrates only on

three methods .Those methods are init(ServletConfig config) service(ServletRequest req,ServletResponse res) ...
Read Answers (2) | Asked by : Ferdousi Answer Question Subscribe

Can anyone briefly explain mvc1 and mvc2 and differences and which is best.
Latest Answer: MVC Describes that each part of responsibiltiesM-Model is responsible for business

process and business dataV-view is responsible for response content to dispatch the clientCController is responsible for to control the requset and response In MVC1, Model ...
Read Answers (8) | Asked by : pbv_krishnamraju Answer Question Subscribe

What is the difference between request.forward and requestdispatcher.forward?


Latest Answer: The question should be like - What is the difference between

requestdispatcher.forward and response.sendredirect? The response will not be sent back to the client and so the client will not know about this change of resource on the server. for ...
Read Answers (5) | Asked by : Navya Answer Question Subscribe

What is the purpose of doPUT() and doDELETE() method?


Latest Answer: doPUT: The PUT method is a complement of a GET request, and PUT stores

the entity body at the location specified by the URI. It is similar to the PUT function in FTP.doDELETE: The DELETE method is used to delete a document from the server. The document ...
Read Answers (2) | Asked by : mail_2_mahendran Answer Question Subscribe

How many objects are created when same or different client send 100 requests to a servlet?
Latest Answer: If the servlet implements SingleThreadModel interface then many instances of

that servlet can be created by the Container otherwise,(i) If the web application is a distributed webapplication then each JVM will have only one servlet instance no matter ...
Read Answers (10) | Asked by : sadashivarao Answer Question Subscribe

Can we have a public default constructor for servlet ?


Latest Answer: Yes , of course you can use the constructor instead of init().Theres nothing to

stop you. But you shouldnt. The original reason for init() was that ancient versions of Java couldnt dynamically invoke constructors with arguments, so there was no way ...
Read Answers (7) | Asked by : Abhijit Datta Answer Question Subscribe

Can a webcontainer creates another cookie eventhough we r set the maxage of already created cookie
Can a webcontainer creates another cookie eventhough we r set the maxage of already created cookie while sending second request within period of setmaxage of that cookie

If we put some request, intially either doget() or dopost() is getting invoked? why not any servlet
If we put some request, intially either doget() or dopost() is getting invoked? why not any servlet life cycle method is not getting invoked?Then why don't we include this doget() and dopost() in the servlet life cycle methods?
Read Answers (7) | Asked by : Roshini Answer Question Subscribe

While using cookies, when the browser is shut down. will the data be available at next open of browser.
While using cookies, when the browser is shut down. will the data be available at next open of browser. If not available, how to over come that.
Read Answers (5) | Asked by : Srini99 Answer Question Subscribe

When destroy method get call, will it call for each user please give the ans in detail?
Latest Answer: 1)when the application is stopped2)when a class is replaced with the new

class3)when there is no memory to operate. ...


Read Answers (6) | Asked by : sachinTest Answer Question Subscribe

What is the diff b/w doGet() and service() method


Latest Answer: When we make a request to the application webcontainer makes the request and

response object and creates the servlet instance.After it calls the servlet life cycles methods like init().After completing the intialization it calls the service()method passing ...
Read Answers (4) | Asked by : ram Answer Question Subscribe

What is pure servlet?


Latest Answer: pure servlet means we create any java objets that is implemented from

javax.servler.Servlet interface. ...


Read Answers (1) | Asked by : B.Purandhar reddy Answer Question Subscribe

How can a web container know whether cookies are accepted or not accepted by the browser
Latest Answer: The only way to know for sure is to set a cookie on a response, and see ifit comes

back on the following request. You have absolutely no clue fromlooking just at the current request. Just as an example, I run Netscape6, configured to warn ...
Read Answers (1) | Asked by : venkat

Answer Question

Subscribe

What is servlet ,what is the use of it?


Latest Answer: hi,Servlet is a webcomponent which is used for the generating dyanamic

content.Because most of the web applications are dynamic in nature .In order to generate the dyanmic content we are using the servlets. ...
Read Answers (8) | Asked by : padmakalyani Answer Question Subscribe

How can we refresh the servlet for every 2 minutes automatically?


Latest Answer: Hi,

you are perfectly right in your explanation. but there is a small mistake in your writting. the refresh header is not a part of request header rather it is a header of response. response.setHeader("Refresh","300; ...
Read Answers (3) | Asked by : sadashivarao Answer Question Subscribe

Why init is used and not constructor for servlets initialization?


Latest Answer: If u used a constuctor then no probs it's working fine but u cant

used servletconfig and u cant passed argument constructor b'coz only first time yr constructor has called and for other request directlly service method called so we cant able to ...
Read Answers (4) | Asked by : javadeep Answer Question Subscribe

Hi Guys, Can we write destroy() method in the init() method of a Servelt. if we can, what will happen?
Hi Guys, Can we write destroy() method in the init() method of a Servelt. if we can, what will happen? if we cant , why we cant?with regards, santh

How you can activate or call one another servlet method?


Latest Answer: Hi,Good to see the ways of communication between servlets.My question goes as:

The servlet communication when they are running in different servlet container. sOne and sTwo are two servlets, here can we include sTwo's output in response of sOne's?Thank ...
Read Answers (4) | Asked by : sudhakar_bvr Answer Question Subscribe

Which method is more advantageous doGET() or doPOST()? in which situation does we use doGET() then?
Latest Answer: doGET() is better ... Read Answers (6) | Asked by : neelima Answer Question Subscribe

When we have the servlets/struts what is the perpose of EJB


Latest Answer: True Aditya... ... Read Answers (2) | Asked by : Nagender Answer Question Subscribe

How to Access Session Variables in Servlets & JSp

Latest Answer: Use can store variables in session, but u can store it in object form only.if it is

primitive type u can use wrapper classes to convert it into object.session.setAttribute("test","xyzp");Stringstr=(String)session.getAttribute("test");while retrieving ...
Read Answers (1) | Asked by : Sandy Answer Question Subscribe

How can i create connection pooling in tomcat?


Latest Answer: we can create connection pooling using tomcatFor that 1. we need to download 3

jar files a. commons-dbcp-1.2.jar b. commons-collections-3.1.jar c. commons-pool-1.3.jar 2. we want to add an entry in server.xml of the tomcat factory org.apache.commons.dbcp.BasicDataSourceFactory driverClassName oracle.jdbc.OracleDriver url jdbc:oracle:thin:@localhost:1521:orcl username anand password pass maxActive 20 maxIdle 10 maxWait -1 for ...
Read Answers (2) | Asked by : rama krishna Answer Question Subscribe

Suppose there are 15 links on the homepage of a site and each link creates a new request, how your servlet
Suppose there are 15 links on the homepage of a site and each link creates a new request, how your servlet controller would handle it? (Assuming you are using MVC-2)
Read Answers (3) | Asked by : Anoop Answer Question Subscribe

What is meant by preintialization?


Latest Answer: when we send any request to the servlet, that request tryies to find servlet 1st.

secondservlet executing following sequence of methodinit()service()destroy()so the 1st time request to servlet, response time is high than 2nd request so to avoid ...
Read Answers (2) | Asked by : adepu Answer Question Subscribe

How to integare struts and hibernate


Latest Answer: Jagmohan,

I am really happy after saw your answer.It is the perfect and Suitable answers.Thanks & Regards,Nagaraju. ...
Read Answers (3) | Asked by : Rupesh Answer Question Subscribe

Suppose number of servlets/jsps from various web applications want to access shared data, what is the
Suppose number of servlets/jsps from various web applications want to access shared data, what is the mechanism to achieve the same?
Read Answers (9) | Asked by : hmashruf Answer Question Subscribe

What will happen when we call the destroy method in the init method? will the servlet exist?

Latest Answer: Hi,The servlet specifications clearly states that we can not explicity destroy the

servlet instance by coding what so ever in destroy method.We can only perform clean up operations.So, if we call the service method in init, it will be called and Say I ...
Read Answers (6) | Asked by : Yogesh Answer Question Subscribe

Can we override the service method?if we can do that then why do we override only doGET()and doPost()
Can we override the service method?if we can do that then why do we override only doGET()and doPost() methods if the servlet is of protocol specific?
Read Answers (5) | Asked by : anandkolam Answer Question Subscribe

What is difference between cgi and servlet in interview point


Latest Answer: cgi and servlets are used to develop webapplication only.cgi is a oldest technique

.the main drawback of cgi is1. starting process is very expensive2. it performs very poor. ...
Read Answers (5) | Asked by : venkata narayana Answer Question Subscribe

What are the types of refrences available in java. How they work
Latest Answer: hi,I apprciate ur answer,if u know jsp then tell me in jsp if there is include

directive element then why they have provided include action element. ...
Read Answers (3) | Asked by : Asif Answer Question Subscribe

What is differents between forword(),include() and sendRedirect()? In which circumtances all are used?
What is differents between forword(),include() and sendRedirect()? In which circumtances all are used? Give Proper Examles.
Read Answers (4) | Asked by : shivam_it3 Answer Question Subscribe

Explain StringBuffers and StringTokenizers?


Latest Answer: String Buffer is peer class of String which provide much of the functionality

of strings. "String represent fixed length immutable character sequences" Where as "String Buffer Represent grow able and writeable character sequences" all string ...
Read Answers (4) | Asked by : roja Answer Question Subscribe

What is the difference betweem getRequestDispatcher() available as part of ServletContext and ServletRequest
What is the difference betweem getRequestDispatcher() available as part of ServletContext and ServletRequest
Read Answers (10) | Asked by : divya_a Answer Question Subscribe

Can we write bussiness methods in servlets? if yes, then how can u access that from out side of the
Can we write bussiness methods in servlets? if yes, then how can u access that from out side of the servlets?
Read Answers (4) | Asked by : sivasivasiva Answer Question Subscribe

What is session ?how to manage the session?


Latest Answer: Session is an object of method maintaining state which is act of preserving the

information from one page to another page. we can manage sessions in two ways using cookies using URL rewriting ...
Read Answers (5) | Asked by : karthik Answer Question Subscribe

How to count how many times aprticular link has been clicked using jsp and javascript
Latest Answer: Hi, Clearly, it depends on the level of details one needs to capture, let's say

XYZ123.com wants to place a promotional ad on a frequently visited page.For simplicity, let's confine to one particular page (say XYZPage.jsp):(a) How many times users visit ...
Read Answers (4) | Asked by : payal kalra Answer Question Subscribe

I can do every thing using jsp itself,then what is the need of using servlet?in which situation ,we
I can do every thing using jsp itself,then what is the need of using servlet?in which situation ,we must use servlet with jsp?
Read Answers (1) | Asked by : Ganesh Answer Question Subscribe

Whats the difference between using invalidate() & sessionDestroyed for sessionclosing.
Latest Answer: session's invalidate method is used when the session will no longer exist or when

for a particular client is leaving the session Eg:during the logout.sessiondestroyed is a method of HttpSessionListener ,and this is called when the session is being ...
Read Answers (1) | Asked by : Shekhar Answer Question Subscribe

How many ways we can destroy the servlet in ur program


Latest Answer: Guys pls refer these ... Please ensure your answer is not mislead some

body..http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/Servlet.htmlpublic void destroy()Called by the servlet container to indicate to a servlet that the servlet is ...
Read Answers (10) | Asked by : nagaraj Answer Question Subscribe

Difference between resultset and rowset

Latest Answer: the ResultSet is closed as soon as the Statement itself is closed, or used to

retrieve another ResultSet. Therefore, the pointer that once provided a handle to the query results is no longer valid, and this is where CachedRowSet comes in. Unlike a ResultSet, ...
Read Answers (2) | Asked by : divya_a Answer Question Subscribe

What is default capacity of connection pool objects in pool of app-server Weblogic and Tomcat webserver?
What is default capacity of connection pool objects in pool of app-server Weblogic and Tomcatwebserver?
Read Answers (4) | Asked by : srikanth.sunjava Answer Question Subscribe

In normal javabean, bean object is serailizable,and Connectuin object is transient object.Then How we
In normal javabean, bean object is serailizable,and Connectuin object is transient object.Then How we using javabean for communnication between Servlet and JSP for data Transfer?
Read Answers (1) | Asked by : srikanth.sunjava Answer Question Subscribe

How can I retrive only IntegerObjects from a vector in which I stored all types of objects
Latest Answer: The example code may help you out.Vector v =

getDataVector();//getDataVector() may be some method where you will put all your objects into vector.int size = v.size();for(int i = 0 ; i
Read Answers (1) | Asked by : Eswar Rao Answer Question Subscribe

Consider a scenario where 2 instances of an appserver are running in a machine. And one application
Consider a scenario where 2 instances of an appserver are running in a machine. And one application has been deployed in the two servers. Does these two applications deployed in two servers use the same JVM or different?
Read Answers (3) | Asked by : Sohamsri Answer Question Subscribe

Consider a scenario in which 4 users are accessing a servlet instance. Among which one user called
Consider a scenario in which 4 users are accessing a servlet instance. Among which one user called destroy() method. What happens to the rest 3 users?
Read Answers (4) | Asked by : Sohamsri Answer Question Subscribe

How can you do ErrorMapping in Action class?


Latest Answer: If u ActionMapping.findForward("Failure") in Action Class. The webcontainer reads

the information in sruts-config.xml and get the error page file.In struts-config.xml ...

Read Answers (1) | Asked by : Sohamsri Answer Question Subscribe

What is the disadvantage of the ServerSideIncludes?


Latest Answer: Disadvantage of SSI There is one down side of Server-Side Includes. They are very

processor intensive. If you don't have a high-powered computer running your web server and you expect to have a lot of traffic, you might want to limit the number of documents ...

What is session tracking ?state the uses of GET and POST request to handle Http request ?
Latest Answer: Session tracking is done to maintain the state, as HTTP is an

stateless protocol.Session tracking can be done in following ways - 1. Cookies.2. Hidden variables.3. URL rewriting.When you use GET, then the data appears in the querystring of the web browser ...
Read Answers (2) | Asked by : kevin uttankar Answer Question Subscribe

How differ servlets from its peer technology?


Latest Answer: 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. ...
Read Answers (1) | Asked by : Devika Bhatt Answer Question Subscribe

What is difference between servlet and ASP?


Latest Answer: Platform and Server IndependenceJSP technology adheres to the Write Once, Run

AnywhereTM philosophy of the JavaTM architecture. Instead of being tied to a single platform or vendor,JSP technology can run on any Web server and is supported by a wide variety ...
Read Answers (2) | Asked by : Devika Bhatt Answer Question Subscribe

Have you used threads in Servelet


Latest Answer: Web container automatically creates a thread for each request. We are not using

explicitly but internally it uses multi threading plz give me the response ...
Read Answers (7) | Asked by : shanthini Answer Question Subscribe

Waht is the difference between Generic servlet and HTTPServlet


give me the answer Latest Answer: Generic servlets extend javax.servlet.GenericServlet. Generic servlets are protocol independent, meaning that they contain no inherent support for HTTP or any other transport protocol. HTTP servlets extend javax.servlet.HttpServlet. These servlets ...
Read Answers (16) | Asked by : selvakumar Answer Question Subscribe

How do to prevent user by viewing secured page by clicking back button when session expired..:)
Latest Answer: 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 ...
Read Answers (1) | Asked by : atqpx Answer Question Subscribe

How do we prevent user to read secured page.. after logout


Latest Answer: Go to this thread on this site

only...http://www.geekinterview.com/question_details/18071implement this and ur problem is solved ...


Read Answers (3) | Asked by : atqp Answer Question Subscribe

What is default Session time out in the servers like Tomcat, Weblogic, JBoss,..etc?
Latest Answer: 30 minute ... Read Answers (6) | Asked by : sumanth Answer Question Subscribe

What is difault http method in http servlet?


Latest Answer: Default method is doGET() not doPOST().. ... Read Answers (4) | Asked by : Balakrishnan Answer Question Subscribe

How can a servlet automatically updated by its data without refreshing?take one example of one sensex
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.

What is send redirect method? and when it is used?


Read Answers (4) | Asked by : tushar Answer Question Subscribe

In servlets, what is the use of sendredirect(),include( ), forward() ?and in applecation level at what
In servlets, what is the use of sendredirect(),include( ), forward() ?and in applecation level at what scnario they will be used i know only that send redircet is of client side. and remaing are severside functions
Read Answers (3) | Asked by : srikanth Answer Question Subscribe

How to get initialization time (init () method)values in servlet?

Latest Answer: getInitParameter() method is available in servletConfig and ServletContext();by

using this method we get values of init parameter and context parameter.ex:for suppose in web.xml we configurelike thisaaaAAAAAget ...
Read Answers (4) | Asked by : raj Answer Question Subscribe

How to get value from init() method in servlet? orhow to get initializaion time values from init() in
How to get value from init() method in servlet? orhow to get initializaion time values from init() in servlet? plz ans !!!!!!!!!!!!!!!!!!!
Read Answers (12) | Asked by : raj Answer Question Subscribe

How we can check in particular page the session will be alive or not?
Latest Answer: use this methodHttpSession session=request.getSession(false);in this case the

web container checks JSessionID is available on behalf of client or not.if session is alive it sends old session id.if session is not available it returns null ...
Read Answers (5) | Asked by : chandu Answer Question Subscribe

In which conditions we have to use the ServletContext


Latest Answer: DataInitialization parameters MIME type Version information Path information is

shared between the servlets as : One servlet puts the data in a well known place,which acts as a container and other servlets access the data from that place.These well known ...
Read Answers (9) | Asked by : kailash Answer Question Subscribe

Suppose in web.xml file we are given 30 and in the servlet program we are given setSessionInActiveInterval(40).when
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?
Read Answers (1) | Asked by : padmaja Answer Question Subscribe

How much amount of information will be stored within a session


Latest Answer: In session you can store data of server RAM size, ofcourse it is available RAM size,

lets say RAM is 128 MB and on booting the system say 28 MB is used By Operating System or other services, then u can store up to 100 mb of data in sessionCheers ...
Read Answers (4) | Asked by : padmaja Answer Question Subscribe

What are the JSP atrributes?


Latest Answer:

Ex,

Actually, jsp must have a attributes, and its can be setted as well as getted. session.setattribute (" "); request.setattribute(" ...
Answer Question Subscribe

Read Answers (5) | Asked by : bharat

I want to know how to encode textbox in servlet so we find complete column information from the database
I want to know how to encode textbox in servlet so we find complete column information from the database

ypes of Servlets?
Latest Answer: Servlets are mainly of two types 1. Genric servlet 2. http servlet Rest all servlet

are directly or indirectly implemimplementing or extending of these two ...


Read Answers (8) | Asked by : vijay Answer Question Subscribe

What is the super class of All servlets?


Latest Answer: servlet super class is the Servlet only.but it is the servlet technology by the

javasoft people already defined in genericclass,http etc like as we wish to create infinate no of servlets can be created with implements Servlet. ...
Read Answers (2) | Asked by : chandu Answer Question Subscribe

How will u pass the argument from one servlet to another servlet?
Latest Answer: we can use forward and include of requset dispatcher and the arguments would

be request and response for these methods ...


Read Answers (2) | Asked by : chandu Answer Question Subscribe

We have two applications in that we have two servlets each.How they(servlets) communicate with each
We have two applications in that we have two servlets each.How they(servlets) communicate with each other ?
Read Answers (8) | Asked by : chandu Answer Question Subscribe

Is servlet is used to create a dynamic webpage or Static webpage or both?


yes both servlet is used to create a static and dynamic webpage,it also create a static webpage using serverside include it is .shtml extension,and so servlet is flexible character. Latest Answer: hiBy using the servlets we can create static webpage and dynamic webpage.But mainly we are using servlet for specially create the dynamic webpage only.byechinnu ...
Read Answers (1) | Asked by : gokulakrishnan Answer Question Subscribe

Can a init(ServletConfig config) method be overrided in servlets?


Latest Answer: Yes. We can override.The init(ServletConfig) method is defined in the Servlet

interface. It has been implemented by the GenericServlet class. The implementation of this init method in the GenericServlet just stores the ServletConfig object in some ...
Read Answers (6) | Asked by : javavikas Answer Question Subscribe

When you have action=get?


Latest Answer: when we are sure that we are going to send certain amount of bytes or

characters upto 400 bytes , we can use GET. If it exceeds that limit we can go for POST. Any number of bytes can be sent over the net as name and value pair and bundled with ...
Read Answers (2) | Asked by : chandu Answer Question Subscribe

What methods will be called in which order?((i.e)service(),doget(),dopost())


Latest Answer: All above are not defining real scinerio.When we are extending HttpServlet then

1st of all doGet() or doPost() will be called then internally it will call to protected service() method and it will generate the response. ...
Read Answers (6) | Asked by : chandu Answer Question Subscribe

What is the importance of deployment descriptor in servlet?


Latest Answer: To configure the web application.. ... Read Answers (6) | Asked by : jayakrishnan Answer Question Subscribe

What is the need of super.init(config) in servlets?


Latest Answer: when i m providing init method in our servlet something like that public void

init() throws Exception(){//do something}then webcontainer search for the init method to call n it find this in our servlet and didnt provide all the things ...
Read Answers (6) | Asked by : chandu Answer Question Subscribe

What method used to add a jsp to the servlet


Latest Answer: The RequestDispatcher.include(req, resp) is used to add a jsp to the servlet. ... Read Answers (1) | Asked by : sushma Answer Question Subscribe

How the server will know (i.e) when it can invoke init, service,destroy methods of servlet life cycle?
How the server will know (i.e) when it can invoke init, service,destroy methods of servlet life cycle?
Read Answers (3) | Asked by : chandu Answer Question Subscribe

What is difference between Servlet and Applet


I don t KNOW
Latest Answer: Applet is a program that resides on Internet server and can be downloaded from

Internet and automatically installed on client machine , runs as a part of a web document or web page.So that means applet also controlled by a server called Internt ...
Read Answers (23) | Asked by : Nilesh Answer Question Subscribe

How many ServletConfig and servlet context objects are present in one application?

Latest Answer: The answers above are not fully correct. The correct answer is1. There is

a servlet configper servlet in an application. (Almost, all got this right)2. There is one ServletContext, per application and per jvm. Per jvm is the missing piece. Its about ...
Read Answers (5) | Asked by : satyasudheer Answer Question Subscribe

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


Latest Answer: Singleton class can be created by defining the class static and making its

constructor private so that no other class can user the new() keyword to create the instance of the singleton class. It will provide a public method which will create or return ...
Read Answers (12) Answer Question Subscribe

Servlet is Java class. Then why there is no constructor in Servlet ? Can we write the constructor
Servlet is Java class. Then why there is no constructor in Servlet ? Can we write the constructor in Servlet
Read Answers (6) Answer Question Subscribe

After converting jsp into servlet which methods are present i.e all 6 methods(jspinit(),_jspService(),jspDestroy(),init(),service(),destroy())
After converting jsp into servlet which methods are present i.e all 6 methods(jspinit(),_jspService(),jspDestroy(),init(),service(),destroy()) or only 3 methods i.e either jsp life cycle methods or servlet lifecycle methods
Read Answers (3) Answer Question Subscribe

How to know whether we have to use JSP or Servlet in our project?


Latest Answer: Servlet is controller and JSP is of more a view so when the project needs more on

view oart we can add JSP other wise both can do the sane thing but in larger projects the servlet code becomes cluttred ...
Read Answers (3) Answer Question Subscribe

Why is that we deploy servlets in a webserver.What exactly is a webserver?


Latest Answer: A Web server handles the HTTP protocol. When the Web server receives an HTTP

request, it responds with an HTTP response, such as sending back an HTML page. To process a request, a Web server may respond with a static HTML page or image, send a redirect, ...
Read Answers (5) Answer Question Subscribe

How to get one Servlet's Context Information in another Servlet?


Access or load the Servlet from the Servlet Context and access the Context Information Latest Answer: ServletContext context = getServletContext(); // set the Sttribute for this context context.setAttribute("name","veeru"); //get the context in another servlet/resorce by context.getAttibute("name"); ...

What is the Servlet Interface?


The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or, more commonly, by extending a class that implements it such as HttpServlet.Servlets-->Generic Latest Answer: It is nothing but an interface which contains set of method names (prototypes).Those are called servlet life cycle methods.init(ServletConfig)getServletConfig()service(SeveletRequest , ServletResponce)distroy()The class whch says itself a servlet class, ...
Read Answers (4) Answer Question Subscribe

If you want a servlet to take the same action for both GET and POST request, what should you do?
Simply have doGet call doPost, or vice versa. Latest Answer: in addition to what veeru mentioned, we can override the service(HttpServletRequest , HttpServletResponse ) method as well. service method takes priority over doGet() and/or doPost(). ...
Read Answers (2) Answer Question Subscribe

What is the difference between ServletContext and ServletConfig?


Both are interfaces. The servlet engine implements the ServletConfig interface in order to pass configuration information to a servlet. The server passes an object that implements the ServletConfig interface Latest Answer: We cannot differentiate ServletContext and ServletConfig, both are interface and each exist for a different purpose.ServletContext contains the all the configuration information of theWebApplication which all the servlets in the application use. The ...
Read Answers (13) Answer Question Subscribe

What are the differences between GET and POST service methods?
A GET request is a request to get a resource from the server. Choosing GET as the "method" will append all of the data to the URL and it will show up in the URL bar of your browser. The amount Latest Answer: 1) Get is Faster than Post..2) Get Is Idempotent i.e same work can be done again and again without harming database...3) Amount of data send is limited to few characters only and are visible in address bar, so sensitive data cannot be sent via GET. ...
Read Answers (14) Answer Question Subscribe

Operations performed on vector are either posing a value into the vector (or) retriving a value from
Operations performed on vector are either posing a value into the vector (or) retriving a value from the vector . which operation is synchronized
Read Answers (3)

Answer Question

Subscribe

When we increase the buffer size in our project using page directive attribute 'buffer' what
When we increase the buffer size in our project using page directive attribute 'buffer' what changes we observe?
Read Answers (1) Answer Question Subscribe

What is difference between sendRedirect() and forward()..? Which one is faster then other and which
What is difference between sendRedirect() and forward()..? Which one is faster then other and which works on server?
Read Answers (9) Answer Question Subscribe

How to communicate between two servlets?


ANS: Two ways:1. Forward or redirect from one Servlet to another.2. Load the Servlet from ServletContext and access methods. Latest Answer: Through RequestDispatcher by obtaining object of type RequestDispatcher by getRequestDispatcher() method of ServletContext but before getting object ofReqestDispatcher we have to first obtain object of type ServletContext by getServletContext() method ...
Read Answers (3) Answer Question Subscribe

What is a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or
What is a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization? Although the SingleThreadModel technique is easy to use, and works well for low volume sites, it does not scale well. If you anticipate your users to increase in the future, you may be better off implementing
Read Answers (1) Answer Question Subscribe

Do we have a constructor in servlet ? can we explictly provide a constructor in servlet programme as


Do we have a constructor in servlet ? can we explictly provide a constructor in servlet programme as in java program ?

What is servlet context and what it takes actually as parameters?


Latest Answer: Sumit Sengar Wrote: Another very important and practical application of

ServletContext that i have come across is that it can be used to hold the object which can generate request independent and non-static data. Suppose we want that our servlet should ...
Read Answers (3) Answer Question Subscribe

What is the difference between JSP and SERVLETS


Latest Answer: Both JSP and Servlets provide dynamic content features. Its difficult to point out

the difference as a JSP is ultimately converted into a Servlet and run on Server. Basically, its the separation of roles played by JSP and Servlet which is important. In ...
Read Answers (10) Answer Question Subscribe

How Servlet Applet communication achieved?


Latest Answer: Servlet - Applet communication can be achieved in the following way.a) Type the

following code in your applet. //The path of the servlet needs to be passed as input param to URL Class. URL urlObj = new URL(http://server/servlet?var1=1&var2=2); ...
Read Answers (3) Answer Question Subscribe

What is the servlet life cycle?


Each servlet has the same life cycle:A server loads and initializes the servlet (init())The servlet handles zero or more client requests (service())The server removes the servlet (destroy()) (some servers Latest Answer: Servlet life cycle defines the life process of the servlet. It has certain methods that comes into existence throughout the utilization of the servlet. Generally newInstance() method creates an object to the class. Similar way, internally the newInstance ...
Read Answers (3) Answer Question Subscribe

What is the difference between servlets and applets?


Servlets are to servers. Applets are to browsers. Unlike applets, however, servlets have no graphical user interface. Latest Answer: Applets do not have main() method... ...
Read Answers (4) Answer Question Subscribe

What are the uses of Servlets?


A servlet can handle multiple requests concurrently, and can synchronize requests. This allows servlets to support systems such as on-line conferencing. Servlets can forward requests to other servers and Latest Answer: Practical Applications for Java Servlets This article is compiled by the IWD Team Source: Developing Java Servlets, James Goodwill, samspublishing.com Servlets What are Java Servlets? Servlets ...
Read Answers (1) Answer Question Subscribe

What is the difference between ServetConfig and ServletContext..?


Latest Answer: SevletConfig is used to give the information during the initializing

period.ServletContext is used for thye communication between the servlet and the servletcontainer thatis to give MIME types.ServletContext is used to access other environments thatis ...
Read Answers (3)

Answer Question

Subscribe

What is the use of ServletConfig and ServletContext..?


Latest Answer: ServletConfig and ServletContext are used to pass technical information from

outside to the servlet. e.g. JDBC driver classes. ServletConfig is limited to the Servlet only and the ServletContext is spread over the complete web application. So ServletContext ...
Read Answers (2) Answer Question Subscribe

Can we call destroy() method on servlets from service method?


destroy() is a servlet life-cycle method called by servlet container to kill the instance of the servlet. The answer to your question is "Yes". You can call destroy() from within the service(). Latest Answer: Yes,we can call destroy method,but it is not recommended to call this method from our code since init(),service(),destroy()'s r servlet lifecycle methods.And in destroy()there will be aconfig variable which will be set to null if we override this ...
Read Answers (2) Answer Question Subscribe

What is the difference between GenericServlet and HttpServlet?


GenericServlet is for servlets that might not use HTTP, like for instance FTP service.As of only Http is implemented completely in HttpServlet. The GenericServlet has a service() method that gets called Latest Answer: 1. Generic Servlet are protocol independent but Http Servlet are protocol dependent.2. Generic Servlet can handles all type of protocols but Http Servlet can handle only http specific protocols.3. In Generic Servlet we have to implement the service ...

Difference between single thread and multi thread model servlet


Answered by Scott on 2005-05-12 10:39:32: A servlet that implements SingleThreadModel means that for every request, a single servlet instance is created. This is not a very scalable solution as most web Latest Answer: Hi,As the name says Singlethread means only one thread, can access the service method of the servlet, to reduce the overhead the servlet container creates pool of servlet instances to handle n number of request that is depend on the servler configurationthankschandra ...
Read Answers (3) Answer Question Subscribe

Which code line must be set before any of the lines that use the PrintWriter?
setContentType() method must be set before transmitting the actual document. Latest Answer: response.setContentType("text/hthl"); line before PrintWriter line. ...
Read Answers (2) Answer Question Subscribe

Can I invoke a JSP error page from a servlet?


Yes, you can invoke the JSP error page and pass the exception object to it from within a servlet. The trick is to create a request dispatcher for the JSP error page, and pass the exception object as a

Latest Answer: 1. How do u difine an error page?2.What r the methods called in servlet life

cycle?3.How can u make session variables un available?4. How to change the port no of agiven application server?5.How do udeploye an EJB in the existing application using webspehere? 6.Why ...
Read Answers (4) Answer Question Subscribe

Can I just abort processing a JSP?


Yes. Because your JSP is just a servlet method, you can just put (whereever necessary) a < % return; % > Latest Answer: I can see, the jsp:forward line did dissapear after your editing.....It should read: If you want a solution similar to the Coldfusion , then do the following: Create a page called exit.jsp etc. with only this content: ...
Read Answers (2) Answer Question Subscribe

How HTTP Servlet handles client requests?


An HTTP Servlet handles client requests through its service method. The service method supports standard HTTP client requests by dispatching each request to a method designed to handle that request. Latest Answer: hi,by using the http methods like get,post etc .to maintain the conversional state of the client by using session tracking,cookie ,hidden techniques,the servlet wii be handle the requests.bye ...
Read Answers (1) Answer Question Subscribe

When a servlet accepts a call from a client, it receives two objects. What are they?
ServeltRequest: which encapsulates the communication from the client to the server.ServletResponse: which encapsulates the communication from the servlet back to the client.ServletRequest and ServletResponse Latest Answer: when a request is sent from the browser to a servlet, the servlet object will be created by the webcontainer if we don't provide load-on-startup element.suppose if we provide load-on-startup element the webcontainer creates the servlet object when ...
Read Answers (2) Answer Question Subscribe

What information that the ServletRequest interface allows the servlet access to?
Information such as the names of the parameters passed in by the client, the protocol (scheme) being used by the client, and the names of the remote host that made the request and the server that received Latest Answer: really, a must-know questions for a j2ee programmer ...
Read Answers (1) Answer Question Subscribe

What information that the ServletResponse interface gives the servlet methods for replying to the client?

What information that the ServletResponse interface gives the servlet methods for replying to the client? It Allows the servlet to set the content length and MIME type of the reply. Provides an output stream, ServletOutputStream and a Writer through which the servlet can send the reply data.
Read Answers (2) Answer Question Subscribe

What is the servlet?


Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet may be responsible for taking data in an HTML order-entry form and applying Latest Answer: A java program that runs on a web server. ...
Read Answers (7) Answer Question Subscribe

What are the advantages using servlets than using CGI?


Servlets provide a way to generate dynamic documents that is both easier to write and faster to run. It is efficient, convenient, powerful, portable, secure and inexpensive. Servlets also address the problem Latest Answer: Java servlets are more efficient, easier to use, more powerful, more portable, and cheaper than traditional CGI and than many alternative CGI-like technologies. (More importantly,servlet developers get paid more than Perl programmers :-). Efficient. ...

What is Servlet?

A servlet is a Java technology-based Web component, managed by a container called servlet container or servlet engine, that generates dynamic content and interacts with web clients via a request\/response paradigm.
Why is Servlet so popular?

Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web server.
What is servlet container?

The servlet container is a part of a Web server or application server that provides the network services over which requests and responses are sent, decodes MIMEbased requests, and formats MIME-based responses. A servlet container also contains and manages servlets through their lifecycle.
When a client request is sent to the servlet container, how does the container choose which servlet to invoke?

The servlet container determines which servlet to invoke based on the configuration of its servlets, and calls it with objects representing the request and response.
If a servlet is not properly initialized, what exception may be thrown?

During initialization or service of a request, the servlet instance can throw an UnavailableException or a ServletException.

Given the request path below, which are context path, servlet path and path info?

/bookstore/education/index.html context path: /bookstore servlet path: /education path info: /index.html
What is filter? Can filter be used as request or response?

A filter is a reusable piece of code that can transform the content of HTTP requests,responses, and header information. Filters do not generally create a response or respond to a request as servlets do, rather they modify or adapt the requests for a resource, and modify or adapt responses from a resource.
When using servlets to build the HTML, you build a DOCTYPE line, why do you do that?

I know all major browsers ignore it even though the HTML 3.2 and 4.0 specifications require it. But building a DOCTYPE line tells HTML validators which version of HTML you are using so they know which specification to check your document against. These validators are valuable debugging services, helping you catch HTML syntax errors.
What is new in ServletRequest interface ? (Servlet 2.4)

The following methods have been added to ServletRequest 2.4 version: public int getRemotePort() public java.lang.String getLocalName() public java.lang.String getLocalAddr() public int getLocalPort()
Request parameter How to find whether a parameter exists in the request object?

1.boolean hasFoo = !(request.getParameter("foo") == null || request.getParameter("foo").equals("")); 2. boolean hasParameter = request.getParameterMap().contains(theParameter); (which works in Servlet 2.3+)
How can I send user authentication information while making URL Connection?

You'll want to use HttpURLConnection.setRequestProperty and set all the appropriate headers to HTTP authorization.
Can we use the constructor, instead of init(), to initialize servlet?

Yes , of course you can use the constructor instead of init(). There's nothing to stop you. But you shouldn't. The original reason for init() was that ancient versions of Java couldn't dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won't have access to a ServletConfig or ServletContext.

How can a servlet refresh automatically if some new data has entered the database?

You can use a client-side Refresh or Server Push


The code in a finally clause will never fail to execute, right?

Using System.exit(1); in try block will not allow finally code to execute.
What mechanisms are used by a Servlet Container to maintain session information?

Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information
Difference between GET and POST

In GET your entire form submission can be encapsulated in one URL, like a hyperlink. query length is limited to 260 characters, not secure, faster, quick and easy. In POST Your name/value pairs inside the body of the HTTP request, which makes for a cleaner URL and imposes no size limitations on the form's output. It is used to send a chunk of data to the server to be processed, more versatile, most secure.
What is session?

The session is an object used by a servlet to track a user's interaction with a Web application across multiple HTTP requests.
What is servlet mapping?

The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to servlets.
What is servlet context ?

The servlet context is an object that contains a servlet's view of the Web application within which the servlet is running. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use. (answer supplied by Sun's tutorial).
Which interface must be implemented by all servlets?

Servlet interface.

Explain the life cycle of Servlet.

Loaded(by the container for first request or on start up if config file suggests load-on-startup), initialized( using init()), service(service() or doGet() or doPost()..), destroy(destroy()) and unloaded.
When is the servlet instance created in the life cycle of servlet? What is the importance of configuring a servlet?

An instance of servlet is created when the servlet is loaded for the first time in the container. Init() method is used to configure this servlet instance. This method is called only once in the life time of a servlet, hence it makes sense to write all those configuration details about a servlet which are required for the whole life of a servlet in this method.

Why don't we write a constructor in a servlet?

Container writes a no argument constructor for our servlet.


When we don't write any constructor for the servlet, how does container create an instance of servlet?

Container creates instance of servlet by calling Class.forName(className).newInstance().


Once the destroy() method is called by the container, will the servlet be immediately destroyed? What happens to the tasks(threads) that the servlet might be executing at that time?

Yes, but Before calling the destroy() method, the servlet container waits for the remaining threads that are executing the servlets service() method to finish.
What is the difference between callling a RequestDispatcher using ServletRequest and ServletContext?

We can give relative URL when we use ServletRequest and not while using ServletContext.
Why is it that we can't give relative URL's when using ServletContext.getRequestDispatcher() when we can use the same while calling ServletRequest.getRequestDispatcher()?

Since ServletRequest has the current request path to evaluae the relative path while ServletContext does not.

Você também pode gostar