This kind of question comes up very often in comp.lang.java.programmer - a couple of specific (and frequently asked) examples are:
The key is to think from the brower's point of view, and design a mockup in statically served files, with some dummy data.
As far as a browser is concerned, it's just talking to a web-server. It doesn't know there's a servlet behind the scenes. From a design point of view, this actually makes things much easier, because it means you can apply all your HTML knowledge when designing servlets.
You can design the user interface, putting in dummy static data
where necessary, and then start writing your servlet so that
it outputs the HTML you've written, and any images needed. Note that
each request only gets one response, so to get a page with two
pictures on it, there are three requests. Firstly, the browser
requests the HTML for the page, eg index.html
Secondly, having read the HTML, it notices that there are two
img tags, so it requests each of the images. As far as
the servlet programmer is concerned, these are separate requests.
With HTTP/1.1 they may come in on the same connection, but that
needn't bother you - just write each image as it's requested, and
you'll be fine.
Frames are similar to images - there's one request for the frameset, then one request per frame. Stick to the idea that each HTML page you've written corresponds to one request, and everything should work like magic.
File f = new File ("myfile.txt");it will be taken as relative to wherever their class file is. Now, leaving aside the fact that if you think it through, that's a pretty odd concept (what if the class is loaded over the network, or in a jar file, or autogenerated?), the thing to do is just avoid truly relative filenames altogether in servlets. Relative files would actually be relative to the working directory of the servlet container. That isn't defined in the servlet specification, and will vary between different containers. The way to overcome this is to use filenames which are relative to a known absolute filename, usually specified in the configuration parameters for a servlet. For instance, I often have a
WorkingDirectoryparameter, and just take all my filenames relative to that - so as far as the Java libraries are concerned I'm using an absolute filename, but I don't have to hardcode any absolute filenames into my servlets.
Back to the main page.