I'm trying to use a Struts2 form tag in an application which is deployed in an app in a WebLogic container, which is "front-ended" by a high-performance web server and WL-plugin. For argument's sake, let's say the app is structured something like this:
(This is obviously an abstraction; I do in fact have a web.xml, struts.xml, and a lib directory packed with the dependency jars I need to start it up.)
So at the docroot, I've got a /technology directory containing JSPs; I've got servlet filters which perform some back-end authentication work, and I'm working on an action which will result in JSP or Velocity output.
The server drives mapped URL requests back to my app using some re-writing rules -- so even though I've deployed my app with the context of /MyApp, the web server brokers requests to my application on any URI matching the www.mysite.com/technology pattern, driving the request to /MyApp/technology. I don't expose the application context path to the end-user.
I've set up /technology/index.action (my action package's namespace is "/technology"), which first hits my IndexAction and returns /technology/index.jsp; this is supposed to render a form which will POST on Submit to /technology/moar.action.
Now, I expect using this:
Would produce this:
Instead, the Struts2 form tag automatically pre-pends my application context path to the URL!
I see how having the Struts2 <s:form /> tag automatically prepend the context path would be useful, if my site's entire application presence was under one web app, but in this case it's critical that this not happen. Is there an attribute in the tag that I'm misunderstanding, or a struts.xml value I need to enable, to suppress the application's context path from being pre-pended in <s:form />'s output URL?
David, that suggests an unexpected limitation of Struts2, in its ability to be used as a framework alongside parallel applications on the same app container.
While many developers I know using Struts (and are all still working with 1.2) do in fact build applications where the context path always ends up being part of the URL, these are either one-application-per-domain apps (and therefore the context is /), or are remote portlet objects. Are there perhaps workarounds, or adapters or interceptors, that can facilitate what I'm trying to do?
For example - is there a way to leverage the <s:url /> tag attribute for "includeContext," or is "includeContext" available as an undocumented attribute in <s:form />?
Better still - as a Committer to Struts, and a member of its Project Management Committee, do you know the reason why this functionality isn't available in the <s:form /> tag? Was it a deliberate design decision, or can we in fact expect this sort of thing to be available on the development roadmap?
There's already an "includeContext" attribute in the form tag, but I don't know which version you're using, or the attribute's history--it's there at least of 2.1.8.
Considering that it apparently already exists, and the workaround is trivial, I wouldn't see the change being backported.
Joined: Apr 16, 2010
That's excellent news, David! I'm delighted that I should be able to use the <s:form /> tag after all. I'll just need to ensure use of Struts 2.1.8.x and higher. I'll try that next.
Joined: Apr 16, 2010
Hello David - Struts 126.96.36.199 doesn't provide support for an includeContext attribute the <s:form /> tag. I know that the Struts 188.8.131.52 Documentation for the <s:form /> tag shows it as a valid attribute, but instead it "falls through" as a <FORM> attribute on the rendered page, and the URL is not modified.
I pulled down a copy of the source code for Struts 184.108.40.206 and compared the org.apache.struts2.views.jsp.ui.FormTag and org.apache.struts2.views.jsp.URLTag classes, and double-checked the javadoc for these; definitely no includeContext in the FormTag class. I'm not sure if this is a wiki-documentation failure, or a failure of a developer to provide the expected method signature for the FormTag object.
Perhaps I'm just not phrasing my question correctly; supposing you needed to provide a Form input, using Struts2, leveraging values in the stack and including some features like the file upload tools. You know your application works on your own desktop, but the deployment environment is a site that will map part of its directory presence to your app. Your context path is, effectively, /technology, not /appName/technology.
(1) override the context path rendered by <s:form />, at an application or action level;
(2) post-process the context path rendered by <s:form />, at an application or action level, or;
(3) use some other combination of tags or techniques to provide the same functionality that the Struts2-rendered form would?
It's one of the three options you listed--I don't understand your reluctance. Sure seems quite a bit easier than your first two.
File a JIRA if you want the improvement--submit a patch if you want to increase the odds: if there's no record of anybody wanting it, and no committers have that particular itch to scratch, it'll never get added (or fixed).
I'm pretty sure it can be--S2 form tags are designed to be used within an S2 application. I think you're *also* over-estimating what the form tag actually does (almost nothing). And considering how easy it is to change it, I don't really see what the big deal is.