Colin Wilson-Salt wrote:
>
> Hi.
>
> I'm writing some jsp files to be the V part of an MVC design.
>
> These jsp files all produce very similar looking output - they all
> produce single column tables with exactly the same layout.
>
> I would like to make all these classes extend a common base class, so
> that I can keep all the shared stuff, like setting the colour for the
> header row of the table etc. all in one place.
>
> We're given <%@ page extends="parentClass" %>, but if we want to make
> the parent class another jsp, is there a way?
>
> How do I specify in my parent jsp which package it will be a part of, so
> I know how to refer to it from the child class?
>
> How can I let the jsp compiler know that the parent class needs to be
> compiled first? javac won't be able to find the class file so will go
> looking for a .java file, and won't know anything about the .jsp.
I don't think you can use another JSP as the base class of a JSP,
due to the problems you describe as well as others. In general, the spec
doesn't recommend using the "extends" attribute.
> Is this all just too much to ask, and should I just write a helper class
> to do the formatting? I could instantiate it in the main page and store
> it in the session, so all the other classes use it for doing formatting
> stuff, leaving me with my formatting code in just one place.
This sounds like a much better approach. Your helper classes could
actually be Java Beans with application scope. Then you don't have
to worry about instantiation overhead, but be careful with making them
thread-safe.
> Also I'm including many of these different views in one big table. If I
> want to make each view a seperate class, I have to include them with
> <jsp:include> rather than <%@ include " %>. From what I understand this
> is almost like making a whole new request on the web server. What is the
> overhead of this, if I'm going to be doing it 10 times in a single page?
> Perhaps we need a form of include which instantiates a new servlet/jsp
> without going through the web server?
<jsp:include> uses the Servlet API RequestDispatcher, so it's all done
by local calls on the server. It's pretty much the same overhead as you
calling a method of another class in a scriptlet (okay, a bit more), far
less than a regular redirect where the client is asked to do a new request
over the net. But if you can find a way to use Java Beans for formatting
it's probably the most efficient way.
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".