1. JSP is actually converted into a servlet by the container. 2. JSP is usually used for displaying the data etc to the user whereas servlets are generally used for back end processing. 3. When a JSP is called for the very first time the response will be slow because of the process of converting it into a servlet and compiling. Thereafter it will be ok.
Architecturally, It's not either/or it's usually both/and. Most systems use both Servlets and JSP's -- Servlets are Controllers (in an MVC Sense) and JSP's are views. Trying to use JSP's as controllers is what often makes all-JSP sites slower. When they are used in the right way, then they're usually not a performance problem. Kyle
Hello Mathew, JSP has the advantage of seperating the presentation layer and business logic, and hence convinient at development. First time when JSP engine encounter JSP request, it convert JSP in servlet, compile it and the bytecode format it saves in JSP Container along with the time stamp. Due to this process the first time response of JSP as compaired to servlets is slower, much slower. But from next request onword JSP engine checks the time stamp of the request and of JSP compiled file in JSP Container in JVM, and if the file is not changed then it redirects this request to that class file. And client get the response. In case of servlet the compiled servlet, ie class files are stored in Servlet Container in JVM. As both servlet and JSP is handled with same processes and sharing the resourses (JVM), there is no difference in performance of both. IF anybody can throw more light on this, then please..
Shashank Hiwarkar wrote:Hello Mathew,
JSP has the advantage of seperating the presentation layer and business logic, and hence convinient at development.
First time when JSP engine encounter JSP request, it convert JSP in servlet, compile it and the bytecode format it saves in JSP Container along with the time stamp.
Due to this process the first time response of JSP as compaired to servlets is slower, much slower.
But from next request onword JSP engine checks the time stamp of the request and of JSP compiled file in JSP Container in JVM, and if the file is not changed then it redirects this request to that class file. And client get the response.
In case of servlet the compiled servlet, ie class files are stored in Servlet Container in JVM.
As both servlet and JSP is handled with same processes and sharing the resourses (JVM), there is no difference in performance of both.
IF anybody can throw more light on this, then please..
Hi Friends,
We can make the application more efficient and decrease the time when the request has been sent for the 1st time
by using the tag <load-on-startup> in web.xml file.
By doing theis the server will convert the jsp to servlet and also create the .class file for the corresponding servlet at the deployment time only.
so, I think its some what a better approach.
If there are any problems by doing so, please let me know.
I'm ready enough to accept my mistakes.
Nam Ha Minh wrote:Servlet is compiled once, whereas JSP may be re-compiled at runtime, so JSP maybe slower than servlet.
Only on the first translation. And it's usually pretty much unnoticeable.
But all of this is micro-optimization. The maintainability you lose by using Servlets rather than JSP is huge, whereas any performance difference will be irrelevant to the end user.
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.