My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
|
servlets Q & A
Posted Date: 17 Mar 2008 Resource Type: Articles/Knowledge Sharing Category: General
|
Posted By: Aparanjitha Member Level: Gold Rating: Points: 5
|
|
|
|
1. 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 the business logic used to update a company's order database.
-Servlets are used to enhance and extend the functionality of Webserver.
-Servlets handles Java and HTML separately.
2. 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 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.
3. What are th characters of Servlet?
As Servlet are written in java, they can make use of extensive power of the JAVA API,such as networking and URL access,multithreading,databaseconnectivity,RMI object serialization.
Efficient : The initilazation code for a servlet is executed only once, when the servlet is executed for the first time.
Robest : provide all the powerfull features of JAVA, such as Exception handling and garbage collection.
Portable: This enables easy portability across Web Servers.
Persistance : Increase the performance of the system by executing features data access.
4. What is the difference between JSP and SERVLETS
Servlets : servlet tieup files to independitently handle the static presentation logic and dynamic business logic , due to this a changes made to any file requires recompilation of the servlet.
- The servlet is Pre-Compile.
JSP : Facilities segregation of work profiles to Web-Developer and Web-Designer , Automatically incorporates changes made to any file (PL & BL) , no need to recompile.
Web-Developer write the code for Bussiness logic whereas Web-Designer designs the layout for the WebPage by HTML & JSP.
- The JSP is Post-Compile.
5. 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 of doing server-side programming with platform-specific APIs. They are developed with Java Servlet API, a standard Java extension.
6. 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.
7. 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 when a client request is made. This means that it gets called by both incoming requests and the HTTP requests are given to the servlet as they are.
GenericServlet belongs to javax.servlet package
GenericServlet is an abstract class which extends Object and implements Servlet, ServletConfig and java.io.Serializable interfaces.
The direct subclass to GenericServlet is HttpServlet.It is a protocol-independent servlet
8. What are the differences between GET and POST service methods?
Get Method : Uses Query String to send additional information to the server.
-Query String is displayed on the client Browser.
Query String : The additional sequence of characters that are appended to the URL ia called Query String. The length of the Query string is limited to 255 characters.
-The amount of information you can send back using a GET is restricted as URLs can only be 1024 characters.
POST Method : The Post Method sends the Data as packets through a separate socket connection. The complete transaction is invisible to the client. The post method is slower compared to the Get method because Data is sent to the server as separate packates.
--You can send much more information to the server this way - and it's not restricted to textual data either. It is possible to send files and even binary data such as serialized Java objects!
9. What is the servlet life cycle?
In Servlet life cycles are,
init(),services(),destory().
Init( ) : Is called by the Servlet container after the servlet has ben Instantiated.
--Contains all information code for servlet and is invoked when the servlet is first loaded.
-The init( ) does not require any argument , returns a void and throws Servlet Exception.
-If init() executed at the time of servlet class loading.And init() executed only for first user.
-You can Override this method to write initialization code that needs to run only once, such as loading a driver , initializing values and soon, Inother case you can leave normally blank.
Public void init(ServletConfig Config) throws ServletException
Service( ) : is called by the Servlet container after the init method to allow the servlet to respond to a request.
-Receives the request from the client and identifies the type of request and deligates them to doGet( ) or doPost( ) for processing.
Public void service(ServletRequest request,ServletResponce response) throws ServletException, IOException
Destroy( ) : The Servlet Container calls the destroy( ) before removing a Servlet Instance from Sevice.
-Excutes only once when the Servlet is removed from Server.
Public void destroy( )
If services() are both for get and post methods.
-So if u want to use post method in html page,we use doPost() or services() in servlet class.
-if want to use get methods in html page,we can use doGet() or services() in servlet calss.
-Finally destory() is used to free the object.
10. What is the difference between ServletContext and ServletConfig?
Both are interfaces.
Servlet Config():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 to the servlet's init() method.
A ServletConfig object passes configuration information from the server to a servlet. ServletConfig also includes ServletContext object.
getParameter( ) , getServletContext( ) , getServletConfig( ), GetServletName( )
Servlet Context(): The ServletContext interface provides information to servlets regarding the environment in which they are running. It also provides standard way for servlets to write events to a log file.
ServletContext defines methods that allow a servlet to interact with the host server. This includes reading server-specific attributes, finding information about particular files located on the server, and writing to the server log files. I f there are several virtual servers running, each one may return a different ServletContext.
getMIMEType( ) , getResourse( ), getContext( ),getServerInfo( ),getServletContetName( )
|
Responses
|
| Author: Deepu 19 Mar 2008 | Member Level: Diamond Points : 2 | Good work Aparanjitha.Keep going eith your postings.Its very nice that you are posting the output alo for the queries.
| | Author: Aparanjitha 19 Mar 2008 | Member Level: Gold Points : 3 | thanks for ur suggestions and encouragement keep on reading my resoucres and give me some more advises . As you said before i want to gain knowledge in all fields and place resources that will be help ful to non cs . Thank you
| | Author: Deepu 19 Mar 2008 | Member Level: Diamond Points : 3 | Sure,I will go on reading your postings.If you go on accepting my advices i will give more advises for your development in the site.Keep going.But just keep in mind that your postings are going to be read by hundreds of people throughout the world.
| | Author: Aparanjitha 19 Mar 2008 | Member Level: Gold Points : 2 | thnx for your reply to my msg. i mine it that my postings will be read by hundreds of people . so im sure that i will place good resources
|
|
Watch TV Channels
|