I came to java world after many years of XML/XSLT based development, and I'm gradually getting more and more suspicious - it looks like I'm missing something really important in java web app building ideology.
This is the way we are building layout in when we are thinking in xslt way: we aggregating all the data we needed in one XML file, which can be transformed into html layout.
In some illustrative pseudo XML-based language it can look something like this:
<data xmlns:x="..." xmlns:xi="...">
<x:get url="http://ourrestapi.net/rrrrrest" xpath="/rest/rest/rest[2]">
<x:param name="sortBy" value="desc" />
</x:get>
<x:get url="http://ourrestapi.net/userdata">
<x:guard test="authorized">
<x:param name="login" value="john" />
</x:guard>
</x:get>
<xi:include href="common.xml" />
</data>
I guess it is enough to illustrate the idea. So, that was the approach I've constantly tried to implement in servlets/jsp world. No surprises, the issue boiled down to the question, which, I believe, is a classical jsp newbie question: "How can I include servlet output at jsp page?"
The correct answer is (correct me if I'm wrong) - I shouldn't. I should use request chaining. As far as I understand (once again, correct me if I'm confusing facts) that means I should call servletA, which put appropriate data to the current request and then forwards it so servletB, and so on. At the end we a redirected to the page with all attributes filled.
As for me, I can name at lest two major difficulties with this approach:
- I should keep somewhere the order of redirects. Whether servletA should now it should redirect to servletB, or some, don't know supervising object should do the job.
- If we are storing everything in request attributes, as Strings, in case we need to parametrize servletB call regarding to data we've get in servletA, we have to provide some tedious serializing/deserializing work.
So, my question is - what is the best approach to add data to JSP page from several different sources.
Excuse me if these questions sound stupid to seasoned JSP developer, the fact is java world is really, really huge and mature, so it is not always easy to find out the truth.