File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Difference in the behaviour of JSP and Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference in the behaviour of JSP and Servlet" Watch "Difference in the behaviour of JSP and Servlet" New topic
Author

Difference in the behaviour of JSP and Servlet

Shahnawaz Shakil
Ranch Hand

Joined: Aug 04, 2008
Posts: 57
Hi,
Perhaps its a simple question but i have this confusion. I am using Netbeans 5.5 IDE with bundled tomcat server. Why it happens that if i make some changes in JSP, i need not to build the project again. Simply clicking on the refresh button of the browser (IE) shows the changes. However if i make some changes in the servlet, i need to build the project again. Is it not strange because afterall even JSP are first translated to java class and consequently to servlet. Then why this difference in their behaviour?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Shahnawaz Shakil:
Hi,
if i make some changes in JSP, i need not to build the project again. Simply clicking on the refresh button of the browser (IE) shows the changes.


no need to save ?
-------------------------------------------------------------------------
the reason is JSP is a precompiled page where the servlet is not
--------------------------------------------------------------------------

Hope This Helps
Shahnawaz Shakil
Ranch Hand

Joined: Aug 04, 2008
Posts: 57
So you mean to say that as soon as we save the JSP file it is translated and compiled automatically?
Thanks for answering.
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
Servers process the JSP and convert into java classes (servlet) during 'runtime'. If your server detects a new version of a JSP is deployed, it processes it, and 'compiles' it as you described.

Servlets are deployed into servers in 'compiled already' format, like as a class file ending in '.class'.

The server wont compile a servlet for you. It expects a compiled one.

You cannot dump a .java (servlet in your case) file into the server and expect the server to compile it.
Shahnawaz Shakil
Ranch Hand

Joined: Aug 04, 2008
Posts: 57
Thanks Jesus, it was helpful
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
Originally posted by Shahnawaz Shakil:
Thanks Jesus, it was helpful


Some IDE, I am not sure if your netbeans version does it, have an option for 'auto build'.

Anytime you save the java class (servlet in your case) while you are inside the IDE and have the 'auto build' turned on, some IDEs would automatically rebuild whatever needs to be rebuilt, and deploy the appropriate files into the server automatically (if server is up) - all happening automatically after you revise a class and click 'save'.
Ajay Vikas
Ranch Hand

Joined: Nov 08, 2006
Posts: 66
Great Jesus you are correct!!!
Servers only expect compiled servlets and makes JSP's turn into java classes. So i believe we should always fresh deploy when we make changes to servlets rather than JSPs.

-vikas.
SCJP 1.4.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference in the behaviour of JSP and Servlet