What is the difference between JSP and servlets?
2013-08-15 15:25
477 查看
A very basic difference:
Servlet is
JSP is
Other diff are:
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
Servlets run faster compared to JSP
JSP can be compiled into Java Servlets
It’s easier to code in JSP than in Java Servlets
In MVC, jsp act as a view and servlet act as a controller.
JSP are generally preferred when there is not much processing of data required. But servlets are best for use when there is more processing and manipulation involved.
The advantage of JSP programming over servlets is that we can build custom tags which can directly call Java beans. There is no such facility in servlets.
We can achieve functionality of JSP at client side by running JavaScript at client side. There are no such methods for servlets.
------------------------------------------------------------------------------
JSP (JavaServer Pages) JSP is a Java view technology running on the server machine which allows you to write template text in (the client side languages like HTML, CSS, JavaScript and so on). JSP supports the so-called taglibs which are backed by pieces of Java code with which you can control the page flow and/or output dynamically (programmatically). A well known taglib is JSTL. JSP also supports Expression Language which can be used to access backend data (actually, the attributes which are available in page, request, session and application scopes), mostly in combination with taglibs.
When a JSP is requested for the first time or when the webapp starts up, the servlet container will compile it into a class extending
Servlets Servlet is an Java application programming interface (API) running on the server machine which can intercept on the requests made by the client and can generate/send a response accordingly. A well known example is the
When a Servlet is requested for the first time or when the webapp starts up, the servlet container will create an instance of it and keep it in memory during webapp's lifetime. The same instance will be reused for every incoming request whose URL matches the servlet's URL pattern. You can access the request data by
Servlet is
html in java
JSP is
java in html
Other diff are:
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
Servlets run faster compared to JSP
JSP can be compiled into Java Servlets
It’s easier to code in JSP than in Java Servlets
In MVC, jsp act as a view and servlet act as a controller.
JSP are generally preferred when there is not much processing of data required. But servlets are best for use when there is more processing and manipulation involved.
The advantage of JSP programming over servlets is that we can build custom tags which can directly call Java beans. There is no such facility in servlets.
We can achieve functionality of JSP at client side by running JavaScript at client side. There are no such methods for servlets.
------------------------------------------------------------------------------
JSP (JavaServer Pages) JSP is a Java view technology running on the server machine which allows you to write template text in (the client side languages like HTML, CSS, JavaScript and so on). JSP supports the so-called taglibs which are backed by pieces of Java code with which you can control the page flow and/or output dynamically (programmatically). A well known taglib is JSTL. JSP also supports Expression Language which can be used to access backend data (actually, the attributes which are available in page, request, session and application scopes), mostly in combination with taglibs.
When a JSP is requested for the first time or when the webapp starts up, the servlet container will compile it into a class extending
HttpServletand use it during the webapp's lifetime. You can find the generated source code in the server's work directory. In for example Tomcat, it's the
/workdirectory. On a JSP request, the servletcontainer will execute the compiled JSP class and send the generated output (usually just HTML/CSS/JS) through the webserver over network to the client side which in turn displays it in the webbrowser.
Servlets Servlet is an Java application programming interface (API) running on the server machine which can intercept on the requests made by the client and can generate/send a response accordingly. A well known example is the
HttpServletwhich provides methods to hook on HTTP requests using the popular HTTP methods such as
GETand
POST. You can configure
HttpServlets to listen on a certain HTTP URL pattern, which is configureable in
web.xml, or more recently with Java EE 6, with
@WebServletannotation.
When a Servlet is requested for the first time or when the webapp starts up, the servlet container will create an instance of it and keep it in memory during webapp's lifetime. The same instance will be reused for every incoming request whose URL matches the servlet's URL pattern. You can access the request data by
HttpServletRequestand handle the response by
HttpServletResponse. Both objects are available as method arguments inside any of the overridden methods of
HttpServlet, such as
doGet()and
doPost().
相关文章推荐
- what is the difference between static and normal variables in c++
- What is the difference between JRE,JVM and JDK?
- What is the difference between SLC and MLC?
- What is the difference between initWithCoder:, initWithNibName:, and awakeFromNib?
- What is the difference between a binary tree, a binary search tree, a B tree and a B+ tree?
- What is the difference between application server and web server?
- What is the difference between SMOD and CMOD?
- What is the difference between an EXE and a DLL?
- What is the difference between extensibility and scalability?
- What is the difference between ControlStyles.DoubleBuffer and ControlStyles.OptimizedDoubleBuffer?
- What is the difference between wc -1 < mydata.dat and wc -1 < mydata.dat ?
- What is the difference between provider network and self-service network in OpenStack?
- What is the difference between a Session and a Cookie?
- What is the difference between char s[] and char *s?
- What is the difference between a pack slip and a pick slip?
- In Linux, what is the difference between “buffers” and “cache” reported by the free command?
- What is the difference between new and malloc()?
- What is the difference between a theorem, a lemma, and a corollary?
- what is the difference between the setTimeout and setInterval
- What is the difference between Listview and Treeview?