JSP/Servlet Design

N

news.anet.com

I have a page called general.jsp which is the URI /general.jsp which
displays some information retrieved from a database. When clicking on a url
in this page it calls a servlet Entry which forwards to entry.jsp to allow
the user to enter data to be displayed by general.jsp upon clicking OK on
the entry.jsp page the user is forwarded to general.jsp. Because this is a
servlet the users URI is /Entry not /general.jsp which is expected.

The question is how does one handle users that want to record a URL to go
back to in the future. If they record /general.jsp then everything will be
fine. If they choose to do it after they add data they will get /Entry
which doesn't know that general.jsp exists only that it fowards where it is
told to.

FYI: I have adopted the Model 2 design in most of my site.

Any help would be appreciated,thanks
Scotchy
 
S

Sudsy

news.anet.com wrote:
The question is how does one handle users that want to record a URL to go
back to in the future. If they record /general.jsp then everything will be
fine. If they choose to do it after they add data they will get /Entry
which doesn't know that general.jsp exists only that it fowards where it is
told to.
<snip>

But that's why you use forward instead of redirect: the URL displayed in
the user's browser doesn't change, no matter where they are in the app.
So they should always go back to the main page if they bookmark any of
the pages.
 
C

Chris Smith

news.anet.com said:
The question is how does one handle users that want to record a URL to go
back to in the future. If they record /general.jsp then everything will be
fine. If they choose to do it after they add data they will get /Entry
which doesn't know that general.jsp exists only that it fowards where it is
told to.

The only way to control the URL that the user agent is requesting to is
to have the first servlet send it a 300-series response via
response.sendRedirect, and then return. The user agent will then read
the response and send a new request for general.jsp (if that's what you
told it to do via the parameter to sendRedirect), and the URL will be
changed.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
S

Scotchy

Chris and Sudsy thanks for the response.

But that's why you use forward instead of redirect: the URL displayed in
the user's browser doesn't change, no matter where they are in the app.
So they should always go back to the main page if they bookmark any of
the pages.

The main problem is the user doesn't go to a Servlet to start with, but a
page. The overall concept is that there are multiple pages that can go to a
single servlet to process data, and then return to the calling page. The
servlet doesn't know except when called from the original page which page to
return to.
I suppose I could do something like /Entry?page=general.jsp but this seemed
a bit hokey. Then if someone records the URL it would send them to where
they came from.

What do you think? I like the Model 2 concept, except for the Forward URL
parts :)
 
T

Tor Iver Wilhelmsen

news.anet.com said:
The question is how does one handle users that want to record a URL to go
back to in the future. If they record /general.jsp then everything will be
fine. If they choose to do it after they add data they will get /Entry
which doesn't know that general.jsp exists only that it fowards where it is
told to.

Try sending a Location: HTTP header.
FYI: I have adopted the Model 2 design in most of my site.

In which case, don't use a browser redirect to /Entry, but a
requestdispatcher redirect, which is internal. In fact, in the Model 2
architecture, most JSPs should be hidden from the user, and the only
URLs they access should be the Frontcontroller servlet, or URL
mappings to this, e.g. the "action.do" stuff mentioned in Sun's Model
2 documents.

http://java.sun.com/blueprints/guid...prise_applications_2e/web-tier/web-tier5.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top