newbie: JSP vs Servlets

Discussion in 'Java' started by Robert Magdziarz, Dec 29, 2006.

  1. 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/
    Robert Magdziarz, Dec 29, 2006
    #1
    1. Advertising

  2. On 29.12.2006 18:48, Robert Magdziarz wrote:
    > 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
    Robert Klemme, Dec 29, 2006
    #2
    1. Advertising

  3. Robert Magdziarz wrote:
    > 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
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Dec 29, 2006
    #3
  4. Does this mean that when I open URL http://localhost/xyz/xyz.jsp the code in
    <% %> is run compiled, not interpreted?

    Uzytkownik "Arne Vajhøj" <> napisal w wiadomosci
    news:45955692$0$49207$...

    > JSP pages get compiled to servlets so performance should
    > be the same.
    Robert Magdziarz, Dec 29, 2006
    #4
  5. Robert Magdziarz wrote:
    > 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
    Robert M. Gary, Dec 29, 2006
    #5
  6. Robert Magdziarz

    Mark Rafn Guest

    >Uzytkownik "Arne Vajhøj" <> napisal w wiadomosci
    >> JSP pages get compiled to servlets so performance should
    >> be the same.


    Robert Magdziarz <> wrote:
    >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.
    --
    Mark Rafn <http://www.dagon.net/>
    Mark Rafn, Dec 29, 2006
    #6
  7. Robert Magdziarz wrote:
    > Uzytkownik "Arne Vajhøj" <> napisal w wiadomosci
    > news:45955692$0$49207$...
    >> JSP pages get compiled to servlets so performance should
    >> be the same.

    >
    > 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?=, Dec 29, 2006
    #7
  8. Robert M. Gary wrote:
    > Robert Magdziarz wrote:
    >> 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.

    >
    > 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
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Dec 29, 2006
    #8
  9. Robert Magdziarz

    R.A.M. Guest

    Is it possible to see source code of the servlet generated?

    Uzytkownik "Arne Vajhøj" <> napisal w wiadomosci
    news:45956ef0$0$49199$...
    > Robert Magdziarz wrote:
    >> Uzytkownik "Arne Vajhøj" <> napisal w wiadomosci
    >> news:45955692$0$49207$...
    >>> JSP pages get compiled to servlets so performance should
    >>> be the same.

    >>
    >> 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
    R.A.M., Dec 30, 2006
    #9
  10. Robert Magdziarz

    Lew Guest

    R.A.M. wrote:
    > 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
    Lew, Dec 30, 2006
    #10
  11. R.A.M. wrote:
    > Uzytkownik "Arne Vajhøj" <> napisal w wiadomosci
    > news:45956ef0$0$49199$...
    >> Robert Magdziarz wrote:
    >>> Uzytkownik "Arne Vajhøj" <> napisal w wiadomosci
    >>> news:45955692$0$49207$...
    >>>> JSP pages get compiled to servlets so performance should
    >>>> be the same.
    >>> 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.

    > 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
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Dec 30, 2006
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Beck

    Threading - ASP. Net vs JSP/Servlets

    Peter Beck, Nov 19, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    684
    S. Justin Gengo
    Nov 19, 2003
  2. Mick
    Replies:
    0
    Views:
    418
  3. Prateeksha Web Services
    Replies:
    0
    Views:
    1,785
    Prateeksha Web Services
    Aug 29, 2003
  4. bigbinc
    Replies:
    1
    Views:
    690
    John C. Bollinger
    Nov 5, 2003
  5. Replies:
    0
    Views:
    4,332
Loading...

Share This Page