Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

November 6, 2009

JSP and SERVLET

difference between JSP and SERVLET

Servlets and Java Server Pages are complementary APIs both providing a means for generating dynamic Web content. Infact JSP's are extensions to servlets which are mainly intended for presentation and to separate presentation from business logic. Functionality wise both are equally good and same.

In Servlets the dynamic content is generated by writing the HTML code embedded in Java code where as in JSP the dynamic content is generated by writing the Java code embedded in HTML code and JSP scriptlets. Finally JSPs are best suit for presentation and servlets are best suit for Controlling purpose


Q : Why is that we deploy servlets in a webserver.What exactly is a webserver?
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, or delegate the dynamic response generation to some other program such as CGI scripts, JSPs (JavaServer Pages), servlets, ASPs (Active Server Pages), server-side JavaScripts, or some other server-side technology. Whatever their purpose, such server-side programs generate a response, most often in HTML, for viewing in a Web browser. Understand that a Web server's delegation model is fairly simple. When a request comes into the Web server, the Web server simply passes the request to the program best able to handle it. The Web server doesn't provide any functionality beyond simply providing an environment in which the server-side program can execute and pass back the generated responses

Why is that we deploy servlets in a webserver.What exactly is a webserver?
When you increase the buffer size in jsp using the buffer tag then it means that you are increasing the data holding capacity of the buffer. When you access the jsp(incresed buffer size) then the user will observe that the page is loaded with data slowly.I means the user can actually see that the page content is being loaded. Its a good practise to use that way coz the user will be at ease.

Syntactically we can a write a constructor in a servlet. But if u write parameterized constructors ensure that u also add zero-arg constructor.If u dont add a zero-arg const. servlet instantiation fails. Infact a constructor doesnt serve any purpose in a servlet except for the zero-arg const. which is used at the time of instantiation of the servlet object.

what is the importance of deployment descriptor in servlet?
The deployment descriptor is not confined to servlets. It belongs to the application. The deployment descriptor basically tell the container where to look out for the resources which patterns to follow how are the resources mapped etc
you can customize web application configuration via the deployment descriptor These configuration include context and servlet initialization parameters servlet loading welcome page session timeout period error page init parameters mime types and can make application distributable.

No comments: