My scenario is that I have a request which is sent in a specific url format to a servlet which downloads a pdf file and streams it back to the browser.
In the servlet, if the url format is different from what is expected but contains all params(a legacy url format bookmarked) then we forward it to a jsp and re-submit to the servlet in the required url format.
This was done because when a pdf opens in the browser, adobe reader couldnt save it using its file name so we have to change the url format so that it takes the name before "?param string" from the new url visible in address bar (forwarding doesn't change url).
So its like request->servlet->jsp->servlet-> servlet streams file to browser.
Since I re-submit in a specific url format which has to be visible in browser address bar, the original request pointing to the source is lost.
Now, if the file to download doesn't exist, we need to set the response code as 404 but that response code doesn't reach the original source which requested it.
If the original source is a standalone class opening a HTTPUrlConnection , it will receive empty headers and responsecode as -1 if the file doesn't exist.
So the requirement is to ensure that we should be able to change the url in address bar and also send the 404 response code if the file doesn't exist to the original source which requested it.