newbie: JSP vs Servlets

R

Robert Magdziarz

Hello,
I have just started learning Java. I have one question: how about
performance of JSP comparing to Servlets? I am using Windows XP and Debian.
/RAM/
 
R

Robert Klemme

Hello,
I have just started learning Java. I have one question: how about
performance of JSP comparing to Servlets? I am using Windows XP and Debian.

JSPs are usually compiled into Servlets, so apart from the initial
compilation hit and a bit of added bookkeeping code there is no
difference. If you observe a difference then I'd say it's usually
caused by what the Servlet / JSP does - but not attributable to the
mechanism.

Regards

robert
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Robert said:
I have just started learning Java. I have one question: how about
performance of JSP comparing to Servlets? I am using Windows XP and Debian.

JSP pages get compiled to servlets so performance should
be the same.

Good or bad performance depends on what you do in them.

Arne
 
R

Robert M. Gary

Robert said:
Hello,
I have just started learning Java. I have one question: how about
performance of JSP comparing to Servlets? I am using Windows XP and Debian.
/RAM/

For me the difference is complexity. If I'm doing something simple I'll
use JSP. However, I don't want to write pages and pages of JSP code
because it gets unmanageable. Also, if you are using embedded frames
<iframe> and are using different MIME types (gif, etc) you need to use
servlets. I have pages I've written that produce a series of dynamic
jfreechart gifs in iframes. I don't think you can do that is JSP.
The problem with using JSP is that there are no good editors for both
the html and the jsp. I use Eclipse to write the jsp and FrontPage to
mange the HTML (apply style sheets etc). So I find myself bouncing
between the two applications against the same file (gotta be careful).

-Robert
 
M

Mark Rafn

Robert Magdziarz said:
Does this mean that when I open URL http://localhost/xyz/xyz.jsp the code in
<% %> is run compiled, not interpreted?

Yes. The JSP container generates Servlet bytecode (sometimes directly,
sometimes by generating java source and compiling it, and sometimes at
build-time rather than on the first request to the server) from the jsp text.

For most servlet containers, this means the first request of a jsp that hasn't
already been compiled can take quite a bit longer than subsequent requests. A
lot of sytems have the option to precompile your JSPs to avoid this behavior,
but you then lose the ability to edit and see changes without rebuilding and
redeploying.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Robert said:
Does this mean that when I open URL http://localhost/xyz/xyz.jsp the code in
<% %> is run compiled, not interpreted?

Not only compiled - tripple compiled !!

First the JSP compiler translates the JSP page to Java source (servlet).

Then the Java compiler translates that Java source to Java byte code.

And when run the JIT compiler translates the Java byte code to
native instructions.

Arne
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Robert said:
For me the difference is complexity. If I'm doing something simple I'll
use JSP. However, I don't want to write pages and pages of JSP code
because it gets unmanageable. Also, if you are using embedded frames
<iframe> and are using different MIME types (gif, etc) you need to use
servlets. I have pages I've written that produce a series of dynamic
jfreechart gifs in iframes. I don't think you can do that is JSP.
The problem with using JSP is that there are no good editors for both
the html and the jsp. I use Eclipse to write the jsp and FrontPage to
mange the HTML (apply style sheets etc). So I find myself bouncing
between the two applications against the same file (gotta be careful).

JSP's can not generate binary stuff.

But the main choice should be based on:
mostly tags => JSP
mostly Java code => servlet + other Java classes
not on complexity.

Arne
 
L

Lew

R.A.M. said:
Is it possible to see source code of the servlet generated [from the JSP]?

Yes. There is a directory in the servlet container installation that contains
the JSPs translated to Jav source. The exact directory location depends on the
container installation. For instance, when I use Netbeans to run JSPs the
generated Java code for the JSPs in an application "sesstest" appears in

~/.netbeans/5.5/apache-tomcat-5.5.17_base/work/Catalina/localhost/sesstest/org/apache/jsp/
.

- Lew
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

R.A.M. said:
> Is it possible to see source code of the servlet generated?

Yes. At least usually.

If you are using a stanldone Tomcat then look in:

<Tomcat root>/work/Catalina/<hostname>/<webapp name>/org/apache/jsp

In JBoss with Tomcat it is:

<JBoss root>/server/<config>\work\jboss.web\<hostname>\<webapp
name>\org\apache\jsp

In WAS I belive that you need to set a configuration parameter
to get it to keep the Java source.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top