-
Servlet vs JSP
I am exploring J2EE. I have basic knowledge of JSP and Servlets but I am confused when to use what. What I know is, what we can do iwit JSP, can also be done with Servlets. So when to use what?
Is there any performance issue related?
Thanks in advance.
-
JSP allows you to embed java code in the HTML.thus, u can create the webpage using the HTML coding and use java code to handle the logic wherever required.
Servlet doesnt allow u to embed java code in the HTML. Servlet is saved as a separate file, and can be accessed from the HTML document.
-
For the basic rule use JSP for the presentation layer where the data should be displayed and it will look, etc. And the servlet is use for a controller to your web application, take a request from user; for instance a JSP page; get the submitted data and save it to the database.
-
hi,
jsp page wen compiled, ll become a servlet only.. and in servlet also u can embed html codes...
use jsp for design
and servlet for bussiness logic......
regards
-
Hei,
Both JSP And Servlet Are ServerSide Components For Serving
Http Requests. But The Purpose Is Defferent.
Use Jsp Wherever you want to display some data to User as
UserInterface. jsp will be used for presentation logic.
Servlet Can Be Used To Implement Controller Logic. That Is to
implement the request-response flow scenarios in your application.
-
Servlets came first. They are just java classes that inherit from some useful base classes can can easily read parameters from a GET/POST command and can write a response to the user/client's browser.
JSP is a way to have something look mostly like HTML interact with servlets.
Anything you can do with JSP pages, you can do by hand with servlets. But JSP makes it easier, and you can use WYSIWYG tools like Dreamweaver to make a jsp page.
And you don't need J2EE all all its evil overhead to use jsp pages and servlets.