I'm rather new to J2EE (though not to Java) and I have a question, I'd like to bounce off of some of you gurus. I have read a number of tutorials but I'm still a bit hazy. Here is the situation.
I've inherited a jsp which generates an html representation of some data stored in a database. I need to modify it such that, if a certain request parameter is passed, in addition to generating the html representation, it will also generate an alternative representation (in pdf) of the data which it will return to the user via a post to a url which will also be specified in a request parameter. So, what I want to do (when these two extra parameters are specified) is first return the HTML representation and then call a separate jsp / servlet which will be responsible for generating the PDF view and posting it back to the client.
My confusion is how to pass control from the initial jsp to my new jsp in such a way that the first jsp won't be blocked on the additional processing and the client will receive the HTML view even as the PDF stuff is cooking. Does this make any sense?
My plan at the moment is to check the parameter in a scriptlet at the very bottom of the jsp and if it's 'true', to use apache HttpClient to post the request to the jsp / servlet (running in the same web app) responsible for generating the PDF. That servlet will then use HttpClient to post the finished product back to the client. I have no idea though if this is really the right way to do this or even if it will work, which is why I'm posting this question. Any comments or suggestions would really be appreciated.
Bear Bibeault wrote:I assume the legacy page is already chock full of outdated scriptlets? Or have you added a scriptlet to a modern JSP page?
How are you preventing the responses from competing?
Yes, the legacy page is very full of scriptlets, very complicated, and has had probably 35 people touch it over the years. So, I'm not going to sweat adding another scriptlet
I don't think that the responses competing are an issue. I should add that the client here, isn't actually an end user at a browswer, but another java program running in a separate web application. They take the html we pass back and display it in an iframe in their application. I've been trying to test some POC code and I'm really not sure if what I'm trying to do makes sense or not. If at the bottom of the jsp I use HttpClient to post to the servlet I'm writing and then let the page complete, what happens to the response to that request? I don't really need it as the whole point of that request is that my new servlet do a post to a URL supplied by the client. But still, it seems kind of dodgy.
Another approach we (myself and the developer of the other web app) talked about was embedding a link in the jsp output, to my new servlet that generates the pdf. The problem here though is that the pdf generation should happen automatically (when the request parameter is set) and not require an end user click. In fact, it doesn't even make sense for the real end user to even see the link. Is there some way that I can specify the URL as part of the response without including it in the html?
Thanks and I apologize for rambling but I'm trying to get this up and running as quick as I can and I just don't have much experience with this stuff.
Bill Smyth wrote: If at the bottom of the jsp I use HttpClient to post to the servlet I'm writing and then let the page complete, what happens to the response to that request?
Exactly, that's what I meant by competing. You've got essentially one request (yes, I know you auto-generate another) and two responses.
If you want the HTML view of the data to appear, and for the end-point browser to display a download dialog for the PDF view automatically, I'd explore embedding a hidden iframe in the JSP whose src is a request to the PDF view. Make sure that the PDF response sets response headers appropriately (content is PDF, disposition is attachment, and so on).