Kevin,

>From my knowledge you can't achieve exactly what you're looking for in
struts2 because struts2 uses the first part of the last section of the url
resource identifier as the key for the action lookup (i.e. for all 4 of your
examples the action would be mapped to he same action for queryName).

I quick and dirty way around this would be to add an extra directory level
for each type, define that as a separate namespace in struts-config, define
the struts filter to handle all relevant extensions in web.xml, and then you
could have the different types. This would give you something like;

http://www.domain.com/struts2/xml/queryName.xml?param1=foo
http://www.domain.com/struts2/json/queryName.json?param1=foo
http://www.domain.com/struts2/html/queryName.html?param1=foo
http://www.domain.com/struts2/rss/queryName.rss?param1=foo

Would this work for you?

Al.

-----Original Message-----
From: Kevin Conroy [mailto:[EMAIL PROTECTED] 
Sent: 24 May 2007 14:42
To: user@struts.apache.org
Subject: [S2] Results Based on URL File Types

Hi everyone,
I'm new to Struts 2 (and Struts in general, for that matter). I've got the
Struts 2 framework up and running and I'm trying to figure out how to get it
to support a use case for our new application. We'd like to have a set of
web services that look like this:

http://www.domain.com/struts2/queryName.xml?param1=foo
http://www.domain.com/struts2/queryName.json?param1=foo
http://www.domain.com/struts2/queryName.html?param1=foo
http://www.domain.com/struts2/queryName.rss?param1=foo

As you can see, the query and its parameters won't change, but we'd like to
alter the result type based on the requested URL file type. How can I best
achieve this in Struts 2? I know that I can do some Apache rewriting to map
these to the correct Actions, but I'd much rather do it in the
struts-config.xml file if I can, that way I can just maintain everything
from one location.

Also, does anyone have any suggestions for best practices on how to handle
different result types? I'd like to reuse some of the same basic framework
pieces to handle all Rss, JSON, etc requests so that when I want to add a
new query to the web service, it's just a matter of adding another Action to
support it, and all of the result types are automatically inherited.

Thanks in advance for your help!
Kevin Conroy


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to