atom feed9 messages in org.apache.struts.userRe: Rewriting the URL in a form:form ...
FromSent OnAttachments
Erik HorstkotteDec 6, 2000 11:47 am 
Colin SampaleanuDec 6, 2000 2:21 pm 
Michael WestbayDec 6, 2000 3:24 pm 
Michael WestbayDec 6, 2000 6:38 pm 
Craig R. McClanahanDec 7, 2000 11:36 am 
Craig R. McClanahanDec 7, 2000 11:36 am 
Erik HorstkotteDec 7, 2000 11:41 am 
Michael WestbayDec 7, 2000 3:54 pm 
Erik HorstkotteDec 7, 2000 6:15 pm 
Subject:Re: Rewriting the URL in a form:form action
From:Craig R. McClanahan (Crai@eng.sun.com)
Date:Dec 7, 2000 11:36:30 am
List:org.apache.struts.user

Michael Westbay wrote:

Horstkotte-san wrote:

There doesn't appear to be any way to cause the URL in a <form:form> tag's "action" parameter to be rewritten using the webapp's context path. As a result, if I use an action="x", it directs the action to x in the current directory, which in my case isn't what I want. If I use an action="/x", it directs the action to the x in the web server's root directory - not the root of my webapp context, which is what I want.

Please try something like:

<form:form action="<%= request.getContextPath() %>/x">

This won't work (invalid tag attribute syntax), but the following will:

<form:form action='<%= request.getContextPath() + "/x" %>'>

Note the use of single quotes on the attribute, to avoid problems with the double quotes used by Java.

While I'm still learning the Struts' tag libraries, I believe that this is the way to do it. I belive that scriplets parse before taglibs, so the result of <%= request.getContextPath() %> will be put into the action attribute before the form:form is parsed. (Please, somebody correct me if I'm wrong on that point.)

I generally use this for things like:

<img src="<%= request.getContextPath() %>/images/logo.gif">

This works because <img> is not a JSP tag, but you might want to recast it in the form that computes the entire expression, so that you can train your fingers to type expressions like this one way in all circumstances.

Hope this helps.

Craig McClanahan