We need to handle Dynamic URL to generate XML based on users request. URL: localhost:4502/feed/[search-term].xml
Ex: localhost:4502/feed/webinar.xml
It should return an xml, which will be generated by system based on search-term mentioned in the URL.
How can we handle such request? I've tried using servlet but it seems sling servlet doesn't support wildcards in the sling.servlet.paths.
Thanks,
Punit Jindal
Solved! Go to Solution.
Views
Replies
Total Likes
Have you included the XML extension in you script name? .html is the default extension so you don't need to include it in script names, but when you need to support other script names they need to be included in the extension. So for example rather than just webinar.jsp you need to name your script webinar.xml.jsp.
Views
Replies
Total Likes
A similar approach to the one orotas mentioned: Do not use selectors, but a suffix, then you could create URLs like http://localhost/feed.xml/searchterm; the implementation is quite identical to the use of selectors, but it might give you some more flexibility.
Jörg
Views
Replies
Total Likes
One approach I know will work is create a page at the URL you want to use and then pass the search term in as with a selector or a query string. The template you case your page off of could be implemented as a servlet - which would potentially be cleaner given you want to generate XML.
Views
Replies
Total Likes
Hi orotas,
I tried using selectors.
URL: "localhost:4502/feed/rss.webinar.html"
Selectors work alright when extension is .html. But, when we use .xml (which is acutally required) instead of .html, selectors do not find the resource.
Note: localhost:4502/feed/rss.xml displays the resource.
Any idea?
Views
Replies
Total Likes
Pjindal,
how does your code look like? It should work irrespective of the extension.
Jörg
Views
Replies
Total Likes
Hi Jörg,
As suggested, I created a page under /content/<site name>/us/en/public/test.
I am able to access the page using: http://localhost:4502/content/<site name>/us/en/public/test.webinar.html.
and http://localhost:4502/content/<site name>/us/en/public/test.xml.
But when I include selector in the 2nd URL, it doesn't return the page.
http://localhost:4502/content/<site name>/us/en/public/test.webinar.xml
-PJindal
Views
Replies
Total Likes
I think you should set response content type as xml like below.
response.setContentType("text/xml;charset=utf-8");
- Subba Rao A
Views
Replies
Total Likes
I tried to set Content Type but to no use. I think my problem can be solved by using suffix instead of selectors, like localhost:4502/feed.xml/[search-term].
But I would need to change extension from .xml to .html after request is submitted by the user. Can you please suggest how can I do that?
Thanks in advance.
PJindal
Views
Replies
Total Likes
Have you included the XML extension in you script name? .html is the default extension so you don't need to include it in script names, but when you need to support other script names they need to be included in the extension. So for example rather than just webinar.jsp you need to name your script webinar.xml.jsp.
Views
Replies
Total Likes
Hi orotos,
It worked. Now am getting control on the required jsp. Thanks a lot for your input.
-PJindal
Views
Replies
Total Likes
Views
Likes
Replies