Hi,
>1. semantics re:forward/back
>Yes, I am *forwarding* BACK to StepA.jsp which knows to grab the bean from
>the session
>and any errors from the request.
ok.
>2. URL displayed on browser command line
>No, this is not a concern at all.
ok.
>3. the problem is - how does the controller know which JSP a request came
>from?
>We know what URL we are POSTing to but not where the POST is coming from.
>As I indicated you can use the REFERER header to get this information BUT
>this header
>changes from "StepA.jsp" to "StepA.do" viz:
YES! I have the exact same problem. I use request.getRequestURI, and it
returns me the action=".." string. Normally, it returns the page that the
request came from..but because we use the .do, it seems to send only the
path of the request, instead of the page. My guess is the only way to work
this in is to match the .do to the .jsp page in the config file, so that you
can do a lookup for the action and know the specific page that sends that
action? Its not exactly what I want to do, but I can't really figure out any
other way to get the getRequestURI or some other method to give me the
path/page.jsp that the form was submitted from.
I see what your trying to do now. You want to forward back to the same page
that sent the form if an error occurs. Again, I have only been able to do
this by hardcoding the link thus far. Infact, what I do, I sort of rigged a
hashtable at this point since I dont haven't got the XML stuff to work yet.
I did something like this in the init method
public class ControllerServlet
extends HttpServlet
{
private ServletContext context = null;
private HashTable forwardTable = new Hashtable();
public static final String EnrollmentOK = "100";
public static final String EnrollmentBAD = "101";
public void init(HttpServletConfig config)
{
forwardTable.add(EnrollmentOK, "/common/enroll_done.jsp");
forwardTable.add(EnrollmentBAD, "/common/enroll.jsp");
}
public void control(HttpServletRequest request, HttpServletResponse
response)
{
String result;
... code to get action, etc..
Action action = ...
result = action.perform(this, request, response);
if( forwardTable.get( result ) != null )
{
.. result is found in lookup table, so froward to the page that is in
the lookup table from the result...
ontext.getRequestDispatcher( forwardTable.get(result)).forward(request,respo
nse);
}
}
}
Ok..the above is not exactly what I do..but it similar. I don't necessarily
like it though..but it does do the job. I have left a bit of code out for
brevity. But, I basically have a result from every action that determines
the forwarding page to go to, and the controller servlet does the
forwarding. Craig, Daniel and a few others put the forwarding code in their
action classes. I disagree with this (my opinion) only because since I know
ALL actions will forward, I would rather "reuse" the forwarding code in one
place, and the ControllerServlet seems to be the best place. In effect..its
the same thing..I just done have more than one forward() call..and none of
the action classes forward directly..they return a result, which could be a
different value depending on what the action does. In the example above, the
Enroll action would return a GOOD or BAD value (100 or 101). Infact, if I
was going to use int values, I would rather store the forwarding classes in
an Array of Strings or something to more quickly find them, or a Hashset,
which is what I will most likely use.
There are probably many ways to do this..but in my case, I haven't found an
alternative to figuring out what page to "forward" back to because the
"request" comes from a .do, and thats not a .jsp. Also, I agree with
you..more than one .do can use the same action. So this still poses as a
problem..how do you get the different .do actions to use a single action
class that forwards to the right pages.
So..if anyone knows..is there a way to get the specific JSP page that the
.do came from?
Hope this helps..and I hope we both can get a better answer.
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets