Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSP newbie - use include, custom tags, standard tags - or what?

Reply
Thread Tools

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

 
 
Mike
Guest
Posts: n/a
 
      01-08-2004
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
 
Reply With Quote
 
 
 
 
Michael Borgwardt
Guest
Posts: n/a
 
      01-08-2004
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.


 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      01-08-2004
Michael Borgwardt <(E-Mail Removed)> wrote in message news:<btjqfj$7sq0m$(E-Mail Removed)-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
 
Reply With Quote
 
Michael Borgwardt
Guest
Posts: n/a
 
      01-09-2004
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP Custom Tags as attribute values for other custom tags Dave Java 0 08-14-2006 02:21 PM
JSF tags enclosed in custom JSP tags? koslows Java 0 05-12-2005 08:09 PM
how to write jsp custom tag that can have all kind of jsp elements(not only other tags but also srciplets) in his body Lukasz Indyk Java 1 09-22-2004 12:43 PM
Custom tags and <jsp:plugin> / <jsp:param> Raymond DeCampo Java 0 02-18-2004 01:29 AM
Custom Tags within Custom Tags. Ranganath Java 2 10-21-2003 06:14 AM



Advertisments