0

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")
2
  • I think that might explain why you can not achieve what you want. stackoverflow.com/a/14020288/7237884 Commented Jan 27, 2021 at 14:03
  • @PanagiotisBougioukos : response.sendRedirect("someFile.jsp?source=" + source + "?target=" +target + "?value=" +value); Can we do like this ? Commented Jan 27, 2021 at 14:32

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

5 Comments

response.sendRedirect("someFile.jsp?source=" + source + "?target=" +target + "?value=" +value); Can we do like this ?
@Som - No, not this way; but there is a workaround. You can put the values into the session object before the redirection and then retrieve them from the session object after the redirection.
like what i have given in OR part ?
@Som - Yes, like what you have added to your question after editing it.
yeah actually i am looking for a workaround..probably ur suggestion might work..let me test it...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.