Howard Moore wrote:

> Seems reasonable. I agree prefix mapping still presents a slight problem but
> pretty well every example I've seen on this list uses extension mapping (as
> I do) so maybe it's not a major issue.
>
> Now all we need to do is get Craig to include it into Struts :-)
>

Just be a little patient with me ... I'll get there ... I promise :-)

Unfortunately, surges of tight deadlines on Tomcat-related issues, plus a nasty
travel schedule, sometimes get in the way :-(.

Craig


>
> > -----Original Message-----
> > From: Chris Smith [mailto:[EMAIL PROTECTED]]
> > Sent: 26 January 2001 11:31
> > To: [EMAIL PROTECTED]
> > Subject: re: FormTag problem
> >
> >
> > You're right, I only considered going from a .jsp to .do
> > within the same
> > path.  Also, I didn't realise I had access to the PageContext
> > from the
> > TagSupport class.  Thanks.
> >
> > I didn't like the idea of adding a slash to the action mapping just
> > because it didn't have one.  I wanted to be able to use relative or
> > absolute mappings, i.e. for the following to be equivalent:
> >
> > /action/logon.jsp contains:
> >   <html:form action="logon.do" ...>
> > or:
> >   <html:form action="/admin/logon.do" ...>
> >
> > I think that's a reasonable way for it to work IMHO.
> >
> > So, to create the action mapping from an action that doesn't
> > start with a
> > slash, I now prepend the path part of the servletPath of the
> > calling jsp.
> >  And for the url in the generated html, if it DOES begin with
> > a slash, I
> > prepend the contextPath (application name) and if it doesn't,
> > leave it alone.
> >
> > So if http://<somehost>/myapp/admin/logon.jsp contains:
> >   <html:form action="logon.do" ...>
> > the action mapping becomes "/admin/logon", and
> > the html contains: action="logon.do"
> >
> > But if http://<somehost>/myapp/admin/logon.jsp contains:
> >   <html:form action="/admin/logon.do" ...>
> > the action mapping becomes "/admin/logon", and
> > the html contains: action="/myapp/admin/logon.do"
> >
> > The extent of my changes are as follows:
> >
> >     /**
> >      * Returns a form action converted into an action mapping path.
> >      * Anything after a period (".") is considered a name
> > extension and
> > ignored.
> >      * If the action doesn't begin with a forward slash
> > ("/"), the path
> > part of
> >      * the servlet path is prepended, giving you a path below
> > the context
> > path.
> >      */
> >     protected String getActionMappingName() {
> >         String retString = action;
> >         int period = action.lastIndexOf(".");
> >         if (period > -1) {
> >             retString = action.substring(0, period);
> >         }
> >         if (retString.charAt(0) != '/') {
> >             String servletPath =
> > ((HttpServletRequest)pageContext.getRequest()).getServletPath();
> >             int slash = servletPath.lastIndexOf("/");
> >             retString = servletPath.substring(0, slash + 1) +
> > retString;
> >         }
> >         return retString;
> >     }
> >
> >     /**
> >      * Returns a form action converted into a url.
> >      * If the action begins with a forward slash ("/"), the
> > context path
> > is
> >      * prepended, otherwise the action is returned unchanged.
> >      */
> >     protected String getActionURL() {
> >         String retString = action;
> >         if (action.charAt(0) == '/') {
> >             retString = ((HttpServletRequest)
> > pageContext.getRequest()).getContextPath() +
> >                 retString;
> >         }
> >         return retString;
> >     }
> >
> > Also, doStartTag() is changed so it calls getActionURL() when
> > generating
> > the action attribute instead of using "action" directly.
> >
> > This works great for extension mapping (my case) :-) but not
> > for prefix
> > mapping (your case) :-(
> >
> > Unfortunately, I don't think there is any way for the FormTag to know
> > what the extension is, so it can't strip it out of the action when
> > creating the action mapping name.  You would have to put the
> > prefix in
> > the action mapping names in struts-config.xml, which is
> > wrong.  I don't
> > know whether some of the other getXXX() methods in HttpServletRequest
> > will be able to help you.
> >
> > Of course all the above assumes you are posting to the same host...!
> > I'll leave that as an exercise for the reader.
> >
> > Sorry for the long post.
> >
> > Chris Smith
> >

Reply via email to