Reputation: 1610
I have the following code in one of my JSP :
<c:redirect url="someFile.jsp">
<c:param name="source" value="${param.source}" />
<c:param name="target" value="${param.target}" />
<c:param name="value" value="${param.value}" />
</c:redirect>
The requested JSP [ someFile.jsp ] access the parameters by the below way :
String source = request.getParameter("source");
String target = request.getParameter("target");
String value = request.getParameter("value");
But instead of <c:redirect url
I need to use response.sendRedirect("someFile.jsp")
method.
But I am not sure how to use the above parameters along with the jsp file name in the sendRedirect method.
Can someone help me out how should I write my redirect method.Can we do something like this :
response.sendRedirect("someFile.jsp?source=" + source + "?target=" +target + "?value=" +value);
OR
session.setAttribute("source",source)
session.setAttribute("target",target)
session.setAttribute("value",value)
response.sendRedirect("someFile.jsp")
Upvotes: 0
Views: 1514
Reputation: 79085
You can not do it using response.sendRedirect
because response.sendRedirect
simply asks the browser to send a new request to the specified path which means the new request won't get any information from the old request.
You can use do it using RequestDispatcher#forward
which forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.
RequestDispatcher dispatcher = request.getRequestDispatcher("someFile.jsp");
dispatcher.forward(request, response);
Upvotes: 1