Bill O'Keefe wrote:
> I have a servlet that reads a list of JSP pages from
> a property I defined (in the 'init' method). When a request
> is sent to my servlet, it uses the RequestDispatcher to
> 'forward' each request it receives to the next page in
> the list. It keeps track of the current page in it's
> session data.
>
> Each JSP presents a form to collect information from the user.
> When the form is submitted, it will create an XML document,
> which it will POST back to my servlet. My servlet will save
> the XML in the session data, then 'forward' the request to
> the next JSP in the list. Once all have been run, my servlet
> will parse and validate the complete XML document that has been
> constructed by each JSP page, then make the appropriate updates
> to a database. It will then reset the session data so that the
> next request will start the process all over again.
>
> Since servlet/JSP/XML programming is still new to me, I am wondering
> if the above approach makes sense, or if there is a better way
> to accomplish the above.
>
In general, this seems like a pretty reasonable approach. If the XML you
create as a result of each form is independent of that created on other forms,
an alternative might be to just collect the input fields in your session, and
then produce the final XML document after the last one has been entered -- but
this is really an issue of which is easier to write and maintain.
>
> One thing I notice when I 'forward' the request to a JSP page
> is that the URL path seems to be set to that of the servlet.
> Thus, even though I forward to a URL in another directory,
> relative references to graphics, etc in the JSP page don't work,
> since they are looked for in /servlet/xxx.gif, which of course,
> doesn't exist. Do I have to include absolute URLs to get this to
> work? Or is there a way to change the pathname in the request?
>
When you do a RequestDispatcher.forward(), the "redirection" happens on the
server side, without the client browser knowing about it. If you really want
the browser URL to change, you can do a sendRedirect() instead, but then
you're paying the performance penalty of an extra round trip across the
network. Users of dynamic web applications (as opposed to your typical web
site) need to understand that the URLs that are displayed are basically
irrelevant, because you can't just bookmark into the middle and proceed from
there. In most cases, I run these kinds of apps in frames (where the visible
URL does not change anyway), or in a new browser window that doesn't even show
the URL, to emphasize the fact that navigation controls on the page are the
only way to move around.
For your image references, the servlet engine will normally let you define a
"default" servlet for the application that is executed when no servlet path
can be found in a URL. If this servlet is a file-serving servlet, then it is
easy to use paths for images (such as "/images/xxx.gif" in a way that is local
to your application. You just need to worry about configuring the associated
servlet context to tell it what the document root directory is. This is, in
fact, how the 2.1 JSDK servlet engine serves static resources, and most other
2.1 engines will have something similar.
>
> -- Bill
>
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html