Re: EJBs vs. Servlets ?!

Discussion in 'Java' started by Razvan, Aug 14, 2004.

  1. Razvan

    Razvan Guest

    > No, why do you think so? Servlets receive requests and sends a
    > response back to the browser (usually). EJBs are often remote objects
    > that expose methods to other Java classes. They are not used for the
    > same thing at all.
    >
    > > The only reason I see to use servlets instead of EJBs is if do
    > > not have an application server (like JBOSS).

    >
    > So, how does a browser call the EJB?


    Thru a JSP, of course.
    This is the reason for JSPs. They take requests from the
    browser, send it to back-end (EJB) get a response and send it back to
    the browser. Where the servlets fit in ?!! Having JSPs and EJB you
    don't need servlets; this being the case, why use servlets at all ?
     
    Razvan, Aug 14, 2004
    #1
    1. Advertising

  2. (Razvan) writes:

    > Thru a JSP, of course.


    Funny guy! JSPs are converted into servlets, which are the components
    the browser interacts with.

    The advantages of using JSP over hand-coded servlets is that a JSP is
    preferred if there is more output than logic, and the tag library
    mechanism is a reasonable way of reusing code.

    > Having JSPs and EJB you don't need servlets; this being the case,
    > why use servlets at all ?


    OK, try using JSPs without a servlet container.

    (Other reasons for using servlets are the Front Controller pattern and
    the Model 2 architecture, used by the very popular Struts web
    application framework among others.)
     
    Tor Iver Wilhelmsen, Aug 14, 2004
    #2
    1. Advertising

  3. On 14 Aug 2004 13:47:47 -0700, Razvan <> wrote:

    >> No, why do you think so? Servlets receive requests and sends a
    >> response back to the browser (usually). EJBs are often remote objects
    >> that expose methods to other Java classes. They are not used for the
    >> same thing at all.
    >>
    >> > The only reason I see to use servlets instead of EJBs is if do
    >> > not have an application server (like JBOSS).

    >>
    >> So, how does a browser call the EJB?

    >
    > Thru a JSP, of course.
    > This is the reason for JSPs. They take requests from the
    > browser, send it to back-end (EJB) get a response and send it back to
    > the browser. Where the servlets fit in ?!! Having JSPs and EJB you
    > don't need servlets; this being the case, why use servlets at all ?


    JSP are designed for createing character streams -> HTML pages
    If you want to serve binary data you should use servlets.
    Why not read about the many roles of servlets here:

    http://java.sun.com/products/servlet/whitepaper.html

    Bill
     
    William Brogden, Aug 15, 2004
    #3
  4. Razvan

    Jim Cochrane Guest

    In article <>, Razvan wrote:
    >> No, why do you think so? Servlets receive requests and sends a
    >> response back to the browser (usually). EJBs are often remote objects
    >> that expose methods to other Java classes. They are not used for the
    >> same thing at all.
    >>
    >> > The only reason I see to use servlets instead of EJBs is if do
    >> > not have an application server (like JBOSS).

    >>
    >> So, how does a browser call the EJB?

    >
    > Thru a JSP, of course.
    > This is the reason for JSPs. They take requests from the
    > browser, send it to back-end (EJB) get a response and send it back to
    > the browser. Where the servlets fit in ?!! Having JSPs and EJB you
    > don't need servlets; this being the case, why use servlets at all ?


    If you're using JSP, you're using servlets (because of the definition of
    JSP). You may not be using them directly, but you're using them.

    --
    Jim Cochrane;
    [When responding by email, include the term non-spam in the subject line to
    get through my spam filter.]
     
    Jim Cochrane, Aug 15, 2004
    #4
  5. Razvan

    Razvan Guest

    > (Razvan) writes:
    >
    > > Thru a JSP, of course.

    >
    > Funny guy! JSPs are converted into servlets, which are the components
    > the browser interacts with.


    Indeed, funny. I am new to all this Java - related
    technologies. After reading your anwser I realised that JSPs are just
    Servlets. This is why there is a small delay when running a JSP for
    the first time - the Java compiler must run first.

    > The advantages of using JSP over hand-coded servlets is that a JSP is
    > preferred if there is more output than logic, and the tag library
    > mechanism is a reasonable way of reusing code.


    When there is less business logic you should use JSPs;
    however, when the business logic is complicated Servlets are better,
    because all the formatting stuff is taking a small percentage of the
    source file.
     
    Razvan, Aug 15, 2004
    #5
  6. Razvan

    Razvan Guest

    "William Brogden" <> wrote in message news:<opscqx24gyk0yerx@ruby>...
    > On 14 Aug 2004 13:47:47 -0700, Razvan <> wrote:
    >
    > >> No, why do you think so? Servlets receive requests and sends a
    > >> response back to the browser (usually). EJBs are often remote objects
    > >> that expose methods to other Java classes. They are not used for the
    > >> same thing at all.
    > >>
    > >> > The only reason I see to use servlets instead of EJBs is if do
    > >> > not have an application server (like JBOSS).
    > >>
    > >> So, how does a browser call the EJB?

    > >
    > > Thru a JSP, of course.
    > > This is the reason for JSPs. They take requests from the
    > > browser, send it to back-end (EJB) get a response and send it back to
    > > the browser. Where the servlets fit in ?!! Having JSPs and EJB you
    > > don't need servlets; this being the case, why use servlets at all ?

    >
    > JSP are designed for createing character streams -> HTML pages
    > If you want to serve binary data you should use servlets.
    > Why not read about the many roles of servlets here:


    So, JSPs can serve only HTML while servlets can serve binary
    also ! You are basically saying that you cannot serve binary data from
    JSPs. Perhaphs you are trying to say that there is no point in doing
    that. Since JSPs practically are servlets, that means they do not have
    any limitations over servlets.
     
    Razvan, Aug 15, 2004
    #6
  7. (Razvan) writes:

    > Indeed, funny. I am new to all this Java - related
    > technologies. After reading your anwser I realised that JSPs are just
    > Servlets. This is why there is a small delay when running a JSP for
    > the first time - the Java compiler must run first.


    Note that you can add <load-on-startup> to a servlet/JSP declaration
    in web.xml to make it compile and instantiate it at startup, which
    prevents the first access taking longer.
     
    Tor Iver Wilhelmsen, Aug 15, 2004
    #7
  8. Tor Iver Wilhelmsen wrote:

    > (Razvan) writes:
    >
    >> Indeed, funny. I am new to all this Java - related
    >> technologies. After reading your anwser I realised that JSPs are just
    >> Servlets. This is why there is a small delay when running a JSP for
    >> the first time - the Java compiler must run first.

    >
    > Note that you can add <load-on-startup> to a servlet/JSP declaration
    > in web.xml to make it compile and instantiate it at startup, which
    > prevents the first access taking longer.


    Yes, you are correct in the case of regular servlets, but the poster
    explicitly mentioned JSPs, which you can not load on startup (unless you
    precompile them).

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, Aug 15, 2004
    #8
  9. On 15 Aug 2004 07:01:10 -0700, Razvan <> wrote:

    > "William Brogden" <> wrote in message
    > news:<opscqx24gyk0yerx@ruby>...
    >> On 14 Aug 2004 13:47:47 -0700, Razvan <> wrote:
    >>
    >> >> No, why do you think so? Servlets receive requests and sends a
    >> >> response back to the browser (usually). EJBs are often remote objects
    >> >> that expose methods to other Java classes. They are not used for the
    >> >> same thing at all.
    >> >>
    >> >> > The only reason I see to use servlets instead of EJBs is if do
    >> >> > not have an application server (like JBOSS).
    >> >>
    >> >> So, how does a browser call the EJB?
    >> >
    >> > Thru a JSP, of course.
    >> > This is the reason for JSPs. They take requests from the
    >> > browser, send it to back-end (EJB) get a response and send it back to
    >> > the browser. Where the servlets fit in ?!! Having JSPs and EJB you
    >> > don't need servlets; this being the case, why use servlets at all ?

    >>
    >> JSP are designed for createing character streams -> HTML pages
    >> If you want to serve binary data you should use servlets.
    >> Why not read about the many roles of servlets here:

    >
    > So, JSPs can serve only HTML while servlets can serve binary
    > also ! You are basically saying that you cannot serve binary data from
    > JSPs. Perhaphs you are trying to say that there is no point in doing
    > that. Since JSPs practically are servlets, that means they do not have
    > any limitations over servlets.


    Whaaaa?
    What I said was that JSP are designed to send character streams,
    not binary data. Practically speaking JSP are limited to sending
    character streams - ie "JSP have limitations over servlets."

    Bill
     
    William Brogden, Aug 15, 2004
    #9
  10. On 14 Aug 2004 13:47:47 -0700, Razvan wrote:

    > Having JSPs and EJB you
    > don't need servlets; this being the case, why use servlets at all ?


    a) JSP's compile to servlets.
    b) Servlets are written in Java, rather than
    an accursed mixture of Java and HTML.

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Aug 16, 2004
    #10
  11. Christophe Vanfleteren <> writes:

    > Yes, you are correct in the case of regular servlets, but the poster
    > explicitly mentioned JSPs, which you can not load on startup (unless you
    > precompile them).


    You would not /normally/ declare JSPs in web-xml, but it's perfectly
    legal:

    <servlet>
    <servlet-name>helpPage</servlet-name>
    *<jsp-file>help.jsp</jsp-file>*
    <load-on-startup>1</load-on-startup>
    </servlet>

    Other reasons for declaring servlet elements that are implemented as
    JSPs are if you want to use getNamedDispatcher() to add a sense of
    semantics to control flow.

    After declaring a JSP as a servlet, you can then use that in any way
    you would any other servlet - add servlet-mappings, filter-mappings
    etc. The only difference is that the servlet is implemented using JSP.
     
    Tor Iver Wilhelmsen, Aug 16, 2004
    #11
  12. Tor Iver Wilhelmsen wrote:

    > Christophe Vanfleteren <> writes:
    >
    >> Yes, you are correct in the case of regular servlets, but the poster
    >> explicitly mentioned JSPs, which you can not load on startup (unless you
    >> precompile them).

    >
    > You would not /normally/ declare JSPs in web-xml, but it's perfectly
    > legal:
    >
    > <servlet>
    > <servlet-name>helpPage</servlet-name>
    > *<jsp-file>help.jsp</jsp-file>*
    > <load-on-startup>1</load-on-startup>
    > </servlet>
    >
    > Other reasons for declaring servlet elements that are implemented as
    > JSPs are if you want to use getNamedDispatcher() to add a sense of
    > semantics to control flow.
    >
    > After declaring a JSP as a servlet, you can then use that in any way
    > you would any other servlet - add servlet-mappings, filter-mappings
    > etc. The only difference is that the servlet is implemented using JSP.


    Thanks for correcting me, I had never seen something like this used before.

    --
    Kind regards,
    Christophe Vanfleteren
     
    Christophe Vanfleteren, Aug 16, 2004
    #12
    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. Patrick May
    Replies:
    3
    Views:
    348
    Sudsy
    Aug 19, 2003
  2. bebonights
    Replies:
    0
    Views:
    361
    bebonights
    Oct 13, 2003
  3. Vjeran Marcinko

    EJBs as active components?

    Vjeran Marcinko, Oct 16, 2003, in forum: Java
    Replies:
    5
    Views:
    498
    Emanuel Bulic
    Oct 17, 2003
  4. Frank Ratzlow
    Replies:
    3
    Views:
    624
    John C. Bollinger
    Nov 11, 2003
  5. Will Hartung

    Re: EJBs vs. Servlets ?!

    Will Hartung, Aug 16, 2004, in forum: Java
    Replies:
    0
    Views:
    1,589
    Will Hartung
    Aug 16, 2004
Loading...

Share This Page