Greger said:
alright,
about to start a project with java servlets. I would appreciate if someone
would highlight do's and don'ts regarding web based apps in java. My plan
is to create a web based database based application with java j2ee, further
I plan to use XML for output ( formatting with XSLT ).
I guess there are some best practices regarding this, if some of you have
experience then post and share your thoughts. Thank's.
Some comments on transferability;
- don't hardcode the deployment directory path into your application
- better yet, don't assume that your application is deployed as
a directory hierarchy -- use the documented interfaces for referring
to resources within your web application
- avoid hardcoding any external directory paths (or URLs, for that matter)
into your application
- pass information on external dependencies as some kind of configuration
variable (system property could be a good way to point to
a configuration file, which then contains data for all external
dependencies)
- use JNDI and container-provided pooling for obtaining database connections
- don't hardcode the application deployment name (context path) into
the application; retrieve it dynamically when/if needed; oftentimes,
the application code shouldn't need it - there are interfaces for
creating proper self-referential URLs
.... at first, the above may feel like unnecessary burden ("this application
will never be relocated"). My experience is that all kinds of reorganisations
happen (directory structures on servers get reorganised, server names or
IP addresses change, external URLs change, database servers change, ...).
If the application has all kinds of external (or even self-referential)
references hardcoded, each transfer will be plainful. On the other hand,
if the application has always been written as transportable, all these
changes are a breeze.
Transportability also eases developing the application with varying
environments (f.ex. separate development, testnig and production
environments). A transportable application doesn't need any change
when taken from one environment to another (thus, there's no risk
of missing a required per-environment change breaking things).