Store the data of interest (query parameters, query attributes, etc.) in Map in the session area using a unique identifier as the key that you add to the return URL.
String id = UUID.randomUUID().toString(); DataOfInterest data = new DataOfInterest(request); Map<String, DataOfInterest> map = (Map<String, DataOfInterest) session.getAttribute("dataOfInterest"); map.put(id, data); returnToUrl += "?token=" + URLEncoder.encode(id, "UTF-8");
And then when it returns, use HttpServletRequestWrapper to wrap the current request, in which you override getParameter() and spouses to return the original data of interest. Do it in Filter .
String id = request.getParameter(token); Map<String, DataOfInterest> map = (Map<String, DataOfInterest) session.getAttribute("dataOfInterest"); DataOfInterest data = map.remove(id); chain.doFilter(new HttpServletRequestWithDataOfInterest(request, data), response);
HttpServletRequestWithDataOfInterest might look like this:
public class HttpServletRequestWithDataOfInterest extends HttpServletRequestWrapper { private DataOfInterest data; public HttpServletRequestWithDataOfInterest(HttpServletRequest request, DataOfInterest data) { super(request); this.data = data; } public String getParameter(String name) { return data.getParameter(name); } public String[] getParameterValues(String name) { return data.getParameterValues(name); }
Note: any obvious feedback from nullcheck, etc. it depends on you.
Balusc
source share