JSP newbie - use include, custom tags, standard tags - or what?

Discussion in 'Java' started by Mike, Jan 8, 2004.

  1. Mike

    Mike Guest

    Hi,
    I have developed a bulletin board using JSP. At the moment all the
    code resides in the JSP pages in scriptlets.

    I understand that it would be advantageous to move a lot of the java
    out of the jsp pages. (Presumably so that a lot of it can be
    precompiled, so that there is more efficiency at runtime - or are
    there other reasons?)

    The book I'm learning from covers scriptlets, then goes on to cover
    including code, writing custom tags, using standard tags...

    As a beginner, I'm trying to gain insight into what would be the best
    approach for my application. From where I'm standing at the moment,
    JSP seems a pretty messy collection of equivalent ways of doing the
    same thing.

    My application requires a good deal of database connectivity, and
    writing of html tables using the results. (Database is MS SQLServer.)
    I'm trying to find an efficient way of using database connections.
    I'm also passing parameters from page to page using variables on the
    end of URLs - e.g. newPage.jsp?t=99&p=2 - should I be using http
    sessions to store this kind of info?

    Any advice on best practice would be much appreciated.
    Mike
    Mike, Jan 8, 2004
    #1
    1. Advertising

  2. Mike wrote:
    > I have developed a bulletin board using JSP. At the moment all the
    > code resides in the JSP pages in scriptlets.
    >
    > I understand that it would be advantageous to move a lot of the java
    > out of the jsp pages. (Presumably so that a lot of it can be
    > precompiled, so that there is more efficiency at runtime - or are
    > there other reasons?)


    Actually, performance has nothing whatsoever to do with it. The main
    point is maintainability. To keep the code understandable and maintainable,
    logic and presentation should be clearly separated. If your JSPs contain
    more Java code than HTML, there is no chance to have HTML specialists
    do the visual design, and even to programmers they will be harder to
    understand.


    > The book I'm learning from covers scriptlets, then goes on to cover
    > including code, writing custom tags, using standard tags...
    >
    > As a beginner, I'm trying to gain insight into what would be the best
    > approach for my application. From where I'm standing at the moment,
    > JSP seems a pretty messy collection of equivalent ways of doing the
    > same thing.


    That's mainly because the "cleaner" ways and in fact JSP itself was
    added after the fact on top of the servlet specification.

    My advice would be to use Servlets to do the logic, flow control and
    DB connectivity and to prepare all necessary data so that the JSPs
    do nothing except display the data. This will vastly improve code
    quality even without using tag libraries. If you want to eliminate
    all Java code from the pages, JSTL should be sufficient; writing
    customs tags is rarely necessary.


    > My application requires a good deal of database connectivity, and
    > writing of html tables using the results. (Database is MS SQLServer.)
    > I'm trying to find an efficient way of using database connections.
    > I'm also passing parameters from page to page using variables on the
    > end of URLs - e.g. newPage.jsp?t=99&p=2 - should I be using http
    > sessions to store this kind of info?


    Only if it's information that is relevant exclusively to that particuar
    user in his current session. URL parameters should still be used to
    hold things that make sense in a URL - a Uniform Resource Locator.
    E.g. for a BBS, it makes sense to have things like "board 3, thread 7"
    in the URL so that it can be bookmarked or given to other people
    who can then jump directly to that thread. But data like "user 246,
    browsing the forum since 12:37" does not belong into a URL but into
    a session.
    Michael Borgwardt, Jan 8, 2004
    #2
    1. Advertising

  3. Mike

    Mike Guest

    Michael Borgwardt <> wrote in message news:<btjqfj$7sq0m$-berlin.de>...

    > My advice would be to use Servlets to do the logic, flow control and
    > DB connectivity and to prepare all necessary data so that the JSPs
    > do nothing except display the data. This will vastly improve code
    > quality even without using tag libraries. If you want to eliminate
    > all Java code from the pages, JSTL should be sufficient; writing
    > customs tags is rarely necessary.


    Thanks for the advice.
    JSP appeals, however, because it generates servlets for me. :) I'm
    afraid learning about writing servlets might add too much time to my
    development schedule. I'll look into it though, and certainly into
    JSTL.
    Cheers,
    Mike
    Mike, Jan 8, 2004
    #3
  4. Mike wrote:
    >>My advice would be to use Servlets to do the logic, flow control and
    >>DB connectivity and to prepare all necessary data so that the JSPs
    >>do nothing except display the data. This will vastly improve code
    >>quality even without using tag libraries. If you want to eliminate
    >>all Java code from the pages, JSTL should be sufficient; writing
    >>customs tags is rarely necessary.

    >
    >
    > Thanks for the advice.
    > JSP appeals, however, because it generates servlets for me. :) I'm
    > afraid learning about writing servlets might add too much time to my
    > development schedule.


    The basic servlet interface is extremely simple, and the more complex
    tasks are equally complex when done in a JSP.
    Michael Borgwardt, Jan 9, 2004
    #4
    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. Raymond DeCampo

    Custom tags and <jsp:plugin> / <jsp:param>

    Raymond DeCampo, Feb 18, 2004, in forum: Java
    Replies:
    0
    Views:
    624
    Raymond DeCampo
    Feb 18, 2004
  2. Lukasz Indyk
    Replies:
    1
    Views:
    1,469
    Andrew Thompson
    Sep 22, 2004
  3. ramakrishna
    Replies:
    0
    Views:
    1,238
    ramakrishna
    May 4, 2006
  4. Replies:
    0
    Views:
    4,354
  5. Dave
    Replies:
    0
    Views:
    450
Loading...

Share This Page