Keep in mind that just as a container dispatches requests to Servlets according to how the Servlets are mapped in web.xml, the Struts controller Servlet dispatches requests to Actions according to how the Actions are mapped in struts-config.xml.
The container asks, which Servlet should I invoke? If it is the Struts controller Servlet, then the controller Servlet will look at the path even more closely and, in turn, ask, which Action should I invoke? An Action might even service three or four different (but similar) URLs, so the pattern can go on within narrower and narrower contexts.
If your controller Servlet is mapped to *.do in web.xml, then the container sees /actor1/usecase1.do and /actor2/usecase3.do as the same -- they are headed for the controller Servlet. But the controller Servlet sees the difference in these -- it will invoke one Action for one and a different Action for the other.
Chuck Chopp wrote:
I'm looking for some good solid examples that show how to configure the JSP files, struts-config.xml [global forwards, action mappings, form beans] and action classes where a JSP may forward/redirect to an action [may end up being a chain of actions] before another JSP is finally displayed. The 2 books that I've been using for learning Struts are "The Struts Framework: A Practical Guide for Java Programmers" by Sue Spielman and "Programming Jakarta Struts" by Chuck Cavaness. Both of these books seem to be lacking solid explanations & examples of the the full range of configurations for forwards & actions. I keep getting the feeling that if I could see one good comprehensive working example everything would be clear to me about how this is supposed to work.
I think you should check out the examples on Rick Reumann's site:
http://www.reumann.net/do/struts/main
I have a welcome file named "index.jsp". I'm questioning if it should be forwarding to the JSP file "login.jsp" [which I want to protect from direct access from the browser] or should it be forwarding to the action named "login" [or would it be "login.do"]?
The link would be to "/login.do". The ".do" portion tells the container to map to the controller Servlet. The "/login" portion tells the controller Servlet which Action to invoke. That action will forward to "/login.jsp".
The action named "login" expects to use "login.jsp" as its input, and I'm just not certain now whether forwarding to a JSP will invoke the action or if forwarding to the action will cause its input form to be displayed.
Also, in my web.xml file, I have a url-pattern of "*.do" set in my servlet-mapping. What I'm not clear on is how/why URLs appear back in the browser such as "login.do" and "success.do" when the global forwards that my actions are using are called by their configured names of "login" and "success". I'm concerned about the browser backward/forward buttons and the reload button being clicked & what this might do to navigation within my webapp.
Say the user's browser has requested "/restrictedpage.do". The container dispatches the request to your Struts controller Servlet. The controller Servlet invokes the "/restrictedpage"Action. The Action determines that the user is not logged in, so instead of forwarding to "/restrictedpage.jsp" as the user might have expected, you instead forward to "/login.jsp". The user's browser is still going to reflect "/restrictedpage.do". You serviced the request -- you sent back some HTML as a response by forwarding to some JSP. The browser didn't care what page on the server the HTML actually came from. If you want the browser to reflect "/login.do", you need to issue a redirect in your Action, instead of a forward. A redirect is a very small response that, instead of including any HTML to display, simply tells the user's browser to make a *different* request -- this time to the login page.
Hope that helps, Erik
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]