I want to know what is difference between servlet and jsp in Java.
Thank you.
I want to know what is difference between servlet and jsp in Java.
Thank you.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Apr 22, 2012, 9:51 AM
Satyapriya NayakPosted Apr 22, 2012, 5:43 AM
Servlets and Java Server Pages are complementary APIs, both providing a means for generating dynamic Web content. A servlet is a Java class implementing the javax.servlet.Servlet interface that runs within a Web or application server's servlet engine, servicing client requests forwarded to it through the server. A Java Server Page is a slightly more complicated beast. JSP pages contain a mixture of HTML, Java scripts (not to be confused with JavaScript), JSP elements, and JSP directives. The elements in a Java Server Page will generally be compiled by the JSP engine into a servlet, but the JSP specification only requires that the JSP page execution entity follow the Servlet Protocol.
The advantage of Java Server Pages is that they are document-centric. Servlets, on the other hand, look and act like programs. A Java Server Page can contain Java program fragments that instantiate and execute Java classes, but these occur inside an HTML template file and are primarily used to generate dynamic content. Some of the JSP functionality can be achieved on the client, using JavaScript. The power of JSP is that it is server-based and provides a framework for Web application development. Rather than choosing between servlets and Java Server Pages, you will find that most non-trivial applications will want to use a combination of JSP and servlets. In fact, the JSP 1.1 and Servlet 2.2 specifications are based around the concept of the Web application, combining the two APIs into a unified framework.
JSP vs Servlet
Java has been a well known name when it comes to software that are used in web development. During the time when static content was no longer enough and more developers began looking for ways to generate dynamic content, Java released the Servlet which is more like a program that is run on the server to provide dynamic pages. Java later released JSP (Java Server Pages) as a more flexible scripting alternative to Java Servlets.
The general advantage of Java Servlets to JSP is the speed at which it can provide response, this is due to the fact that is already compiled and running. JSP code needs to be run through an interpreter that actually generates the HTML or XML code and this is where time is lost, as it goes through the interpreter.
Since both JSP and Servlet are from Java, it is not that difficult to translate one into the other. This is done with the use of a translator like Tomcat and the resulting code can then be compiled into a servlet. This lets web developers create JSP pages and compile them into a java servlet once a user accesses that page. It might take considerably longer to load at first, but consequent loading would be much faster because instead of going back to the JSP page and going through the translation and compiling stages, the running servlet can now handle all requests. Part of the reason why coders like to write in JSP rather than in Java is the relatively easier coding in JSP. Since Java is a programming language for applications, coders need to conform to very strict guidelines, unlike in JSP which is a scripting language.
Nowadays, people use JSP and Java servlets together to provide dynamic content. They prefer the easy coding experienced with JSP while avoiding the compile/debug cycle that is associated with programming languages. They also like the speed advantage provided by servlets and on the fly translation and compiling has become a usual practice in creating dynamic content with JSP and Java servlets.
Summary:
1.JSP is a webpage scripting language that can generate dynamic content while Servlets are Java programs that are already compiled which also creates dynamic web content
2.Servlets run faster compared to JSP
3.JSP can be compiled into Java Servlets
4.It's easier to code in JSP than in Java
5.JSP and Java Servlets are usually used in conjunction nowadays
Read more: Difference Between JSP and Servlet | Difference Between | JSP vs Servlet http://www.differencebetween.net/technology/difference-between-jsp-and-servlet/#ixzz1slEETHKA
Please refer the below link
http://www.differencebetween.net/technology/difference-between-jsp-and-servlet/
Thanks