tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bojan Smojver <bo...@binarix.com>
Subject Re: How to servlets with scope of page?
Date Sat, 27 Apr 2002 02:17:03 GMT
Well, servlets don't really have scope, just like JSP's don't have
scope. The beans used in JSP's have scope, if I remember correctly from
my JSP days.

Anyway, I can describe at least one solution to the problem. For that,
you can download my PumpServlet from here:

ftp://ftp.binarix.com/pub/pump/pump.tar.gz (it is licensed GPL).

It works with Velocity, which you can get from here (currently version
1.2):

http://jakarta.apache.org/velocity/.

The idea is to have an XML file fed into this servlet (which is the only
servlet I ever use in all my applications), which specifies the beans by
scope: application, session and request (page doesn't make sense in this
scenario, so it doesn't exist). The servlet then makes sure that the
beans are loaded and initialised at the correct time and available to
the rendering engine through Velocity context. What's even better is
that you can plug in a Controller right smack in the middle of the
servlet by just specifying it in the web.xml file of your application.
The web.xml file can look the same for all your applications since there
is only one servlet and you can use the same name for the controller
class, since the class loaders are separate for each app. And you get an
MVC (or Model 2) scenario straight away. Also your Velocity pages start
behaving like pages, not like servlets (through a simple mapping in
web.xml), but without all the pitfalls of JSP's. If Model 2 is too
complicated in the beginning, you can always use the servlet with Model
1, there are no restrictions there.

The basic premises of this approach are:

- MVC is good and clean
- designers should design and programmers should program (i.e. allowing
designers to insert arbitrary Java code into the application through
JSP's sucks)
- mucking around with servlets is not cool
- 'real' work is done in 'regular' Java (i.e. you don't have to follow a
another complicated API)

You can find far more information in the README file of the tarball.
And, of course, make sure you're up to speed with Velocity. I can
guarantee that you can master VTL (Velocity Template Language) in one
afternoon :-)

Have fun,
Bojan

On Sat, 2002-04-27 at 01:41, Roland wrote:
> How can I make a servlet with scope of page or any other scope like those 
> defined for jsp? I'm using pure servlets, no JSP.
> 
> Thanks for any help
> Roland
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>
> 



--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message