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

M

Mike

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
 
M

Michael Borgwardt

Mike said:
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.
 
M

Mike

Michael Borgwardt said:
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
 
M

Michael Borgwardt

Mike said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top