jsp servlet code seperation confusion

Discussion in 'Java' started by Martman, Dec 4, 2004.

  1. Martman

    Martman Guest

    I posted this on the .help NG but I believe you folks could probably
    provide more of an accurate answer considering the help group is
    targeted towards true beginners.

    Okay, where I am employeed I have the options of programming with
    Microsoft Technologies and Java specifically J2EE. I have been
    investigating the task of learning Java for about the last 3 to 4
    months. I am a ASP.Net developer fulltime at work with C#. I was new to
    OOP when I started into .Net about a year ago and am getting better.
    However, our corporation uses Java as a National standard and I am
    looking to advance some day and need to learn Java. Furthermore, where I
    live, KY there are very few jobs for technologies other than .Net and
    Java. No PHP or ColdFusion.

    In the last couple of years this code seperation theory has overloaded
    the programming world. .Net does it with what's called code behind. In
    my research of Java the only things I see that reference code seperation
    is servlets (I am sure J2EE and EJB contribute also). However,
    everything I have read on servlets reference outputing HTML back to the
    browser via the HttpServletResponse and Request objects.

    My question, why in the world do they consider outputting HTML back to a
    browser via a servlet considered code seperation. Furthermore, it
    seems very time consuming and difficult to hand code complex layouts in
    HTML and incorporate/format it for a servlet.

    Can someone please explain or direct me to a resource where I can
    understand why using servlets at any point in an application would be
    better than jsp or even applets? Sometimes it's hard enough to design
    complex layouts with the assistance Dreamweaver for example.

    Thanks for any insight you can provide, I have read hundreds of pages of
    information concerning this and trying to compare it with the my current
    knowledge in the .Net world.

    Marty U.
     
    Martman, Dec 4, 2004
    #1
    1. Advertising

  2. Martman

    Anzime Guest

    Martman wrote:
    > I posted this on the .help NG but I believe you folks could probably
    > provide more of an accurate answer considering the help group is
    > targeted towards true beginners.
    >
    > Okay, where I am employeed I have the options of programming with
    > Microsoft Technologies and Java specifically J2EE. I have been
    > investigating the task of learning Java for about the last 3 to 4
    > months. I am a ASP.Net developer fulltime at work with C#. I was new to
    > OOP when I started into .Net about a year ago and am getting better.
    > However, our corporation uses Java as a National standard and I am
    > looking to advance some day and need to learn Java. Furthermore, where I
    > live, KY there are very few jobs for technologies other than .Net and
    > Java. No PHP or ColdFusion.
    >
    > In the last couple of years this code seperation theory has overloaded
    > the programming world. .Net does it with what's called code behind. In
    > my research of Java the only things I see that reference code seperation
    > is servlets (I am sure J2EE and EJB contribute also). However,
    > everything I have read on servlets reference outputing HTML back to the
    > browser via the HttpServletResponse and Request objects.
    >
    > My question, why in the world do they consider outputting HTML back to a
    > browser via a servlet considered code seperation. Furthermore, it seems
    > very time consuming and difficult to hand code complex layouts in HTML
    > and incorporate/format it for a servlet.
    >
    > Can someone please explain or direct me to a resource where I can
    > understand why using servlets at any point in an application would be
    > better than jsp or even applets? Sometimes it's hard enough to design
    > complex layouts with the assistance Dreamweaver for example.
    >
    > Thanks for any insight you can provide, I have read hundreds of pages of
    > information concerning this and trying to compare it with the my current
    > knowledge in the .Net world.
    >
    > Marty U.


    I haven't looked at .Net at all, so I everything I say is from
    a Java perspective.

    You wouldn't want to hard code HTML in a servlet; it's ugly, and
    difficult to maintain. Servlets are great for non-visual applications
    where you need HTTP support (request, response, etc).

    When you mention code separation I think you are talking about
    separting the "display code", "business logic", and "control logic".
    There are many tutorials on the web that mention "Model2"
    development; a derivation of "MVC". Also, their are many frameworks
    to choose from to assist your development. Regardless, it all boils
    down to discipline and proper thinking. Think in layers and OO,
    e.g. how can you separate the "model" (data), from the
    "view" (display), from the "control" (logic); all comprise the
    term MVC.

    Alone, Java Server Pages (JSP) can be misused by incorporating
    Java code as scriplets; doing everything from database connections
    to business logic and application flow. A better approach would be
    to only put HTML in JSPs and use Java tags to display dynamic data.
    Your data would go in Java classes that follow the bean convention
    with private fields and public getters and setters. Your
    business and application logic would go in other classes; packaged
    appropriately. While you're at it, you might as well look at
    decoupling further by putting logic in a set of classes, creating
    handlers that call DAO classes that handle database accesses, etc.

    There are many ways to slice an application. I recommend looking
    into the Apache Struts framework; It's well documented and would
    be a good learning experience.

    On top of all that, you still have many other areas to apply the
    same principles: EJBs, RMI, etc.

    --
    Regards,
    Anzime
     
    Anzime, Dec 4, 2004
    #2
    1. Advertising

  3. Martman

    Martman Guest

    Anzime wrote:
    > Martman wrote:
    >
    >> I posted this on the .help NG but I believe you folks could probably
    >> provide more of an accurate answer considering the help group is
    >> targeted towards true beginners.
    >>
    >> Okay, where I am employeed I have the options of programming with
    >> Microsoft Technologies and Java specifically J2EE. I have been
    >> investigating the task of learning Java for about the last 3 to 4
    >> months. I am a ASP.Net developer fulltime at work with C#. I was new
    >> to OOP when I started into .Net about a year ago and am getting
    >> better. However, our corporation uses Java as a National standard and
    >> I am looking to advance some day and need to learn Java. Furthermore,
    >> where I live, KY there are very few jobs for technologies other than
    >> .Net and Java. No PHP or ColdFusion.
    >>
    >> In the last couple of years this code seperation theory has overloaded
    >> the programming world. .Net does it with what's called code behind. In
    >> my research of Java the only things I see that reference code
    >> seperation is servlets (I am sure J2EE and EJB contribute also).
    >> However, everything I have read on servlets reference outputing HTML
    >> back to the browser via the HttpServletResponse and Request objects.
    >>
    >> My question, why in the world do they consider outputting HTML back to
    >> a browser via a servlet considered code seperation. Furthermore, it
    >> seems very time consuming and difficult to hand code complex layouts
    >> in HTML and incorporate/format it for a servlet.
    >>
    >> Can someone please explain or direct me to a resource where I can
    >> understand why using servlets at any point in an application would be
    >> better than jsp or even applets? Sometimes it's hard enough to design
    >> complex layouts with the assistance Dreamweaver for example.
    >>
    >> Thanks for any insight you can provide, I have read hundreds of pages
    >> of information concerning this and trying to compare it with the my
    >> current knowledge in the .Net world.
    >>
    >> Marty U.

    >
    >
    > I haven't looked at .Net at all, so I everything I say is from
    > a Java perspective.
    >
    > You wouldn't want to hard code HTML in a servlet; it's ugly, and
    > difficult to maintain. Servlets are great for non-visual applications
    > where you need HTTP support (request, response, etc).
    >
    > When you mention code separation I think you are talking about
    > separting the "display code", "business logic", and "control logic".
    > There are many tutorials on the web that mention "Model2"
    > development; a derivation of "MVC". Also, their are many frameworks
    > to choose from to assist your development. Regardless, it all boils
    > down to discipline and proper thinking. Think in layers and OO,
    > e.g. how can you separate the "model" (data), from the
    > "view" (display), from the "control" (logic); all comprise the
    > term MVC.
    >
    > Alone, Java Server Pages (JSP) can be misused by incorporating
    > Java code as scriplets; doing everything from database connections
    > to business logic and application flow. A better approach would be
    > to only put HTML in JSPs and use Java tags to display dynamic data.
    > Your data would go in Java classes that follow the bean convention
    > with private fields and public getters and setters. Your
    > business and application logic would go in other classes; packaged
    > appropriately. While you're at it, you might as well look at
    > decoupling further by putting logic in a set of classes, creating
    > handlers that call DAO classes that handle database accesses, etc.
    >
    > There are many ways to slice an application. I recommend looking
    > into the Apache Struts framework; It's well documented and would
    > be a good learning experience.
    >
    > On top of all that, you still have many other areas to apply the
    > same principles: EJBs, RMI, etc.
    >


    Hey thanks Anzime that really helps. You actually answered more than my
    intentions with my poorly structured question. My main concern was to
    seperate code from presentation and I just forgot to add the word
    presentation to my question.

    The good thing is you gave me a key bit of information that I needed to
    help understand the code/presentation seperation concept.

    Would you happen to have a link to a page that has a good info doc that
    would help me understand using Java tags in jsp pages. I have searched
    google but with the lack of knowledge I don't know if they are
    explaining what you are referencing nor how well they are actually
    explaining it.

    Thanks again, big help

    Marty U
     
    Martman, Dec 4, 2004
    #3
  4. Martman

    Ryan Stewart Guest

    "Martman" <> wrote in message
    news:zyisd.190557$HA.170068@attbi_s01...
    [...]
    > Would you happen to have a link to a page that has a good info doc that
    > would help me understand using Java tags in jsp pages. I have searched
    > google but with the lack of knowledge I don't know if they are explaining
    > what you are referencing nor how well they are actually explaining it.
    >

    They're called custom tag libraries. Try here for starters:
    http://java.sun.com/products/jsp/tutorial/TagLibrariesTOC.html
     
    Ryan Stewart, Dec 4, 2004
    #4
  5. Martman wrote:
    > In the last couple of years this code seperation theory has overloaded
    > the programming world. .Net does it with what's called code behind. In
    > my research of Java the only things I see that reference code seperation
    > is servlets (I am sure J2EE and EJB contribute also). However,
    > everything I have read on servlets reference outputing HTML back to the
    > browser via the HttpServletResponse and Request objects.


    Then your sources are bad or you misunderstood something. The idea is to
    separate display-related code from the program logic and use JSPs for
    (and *onyl* for) rendering HTML pages, while servlets and regular Java
    classes handle the program logic.
     
    Michael Borgwardt, Dec 4, 2004
    #5
  6. Heiner Kücker, Dec 4, 2004
    #6
    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. Mike

    3-tier data layers seperation

    Mike, Feb 28, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    480
    Joe Fallon
    Mar 1, 2005
  2. circuit_breaker
    Replies:
    2
    Views:
    2,094
    Jack Jia
    Apr 4, 2004
  3. javadev
    Replies:
    5
    Views:
    13,095
    javadev
    Nov 16, 2006
  4. Replies:
    4
    Views:
    852
  5. Charles Comstock

    Newsgroup / Mailing List seperation?

    Charles Comstock, May 28, 2004, in forum: Ruby
    Replies:
    1
    Views:
    127
Loading...

Share This Page