sujit
sujit

Reputation: 261

redirect to a different url

I have one application where i have three jsp pages, from index.jsp , control goes to process.jsp and after execution control goes to result.jsp to display data. But i want that instead of displaying data in result.jsp, control will go to another url so that that receiver url will get the requested data. that is: my url is 100.20.3.45:8085/myproject/index.jsp then after processing data i want that result should go to a different url of my same network i.e. 100.20.3.46. How can I send the requested data to this different url?

Ex:

100.20.3.45:8085/myproject/index.jsp

goes to

100.20.3.45.8085/myproject/process.jsp

after processing control will go to 100.20.3.46.

How can I send this data to a different url? what is this mechanism called?

Upvotes: 3

Views: 43442

Answers (2)

Gass
Gass

Reputation: 9402

Redirect to URL

window.location.href = "url"

Examples of use

window.location.href = "/process_payment";
var username = @json($username);
window.location.href = '/' + username;
window.location.href = '/{{ $username }}';

Upvotes: 0

BalusC
BalusC

Reputation: 1109645

It's called "redirecting". It's to be achieved by HttpServletResponse#sendRedirect().

response.sendRedirect(url);

If you want to send additional data along, you'd need send it as request parameter(s) in a query string, but they will be visible in the URL in browser's address bar. If that isn't affordable, consider storing it in a shared datastore (database?) and then pass alone the unique key along.

Alternatively, you can also just let the <form> action URL point to that different host directly without the need for an intermediate JSP. As another alternative, you could also play for proxy yourself with help of for example URLConnection.


Unrelated to the concrete problem: having controller/business logic in JSPs is a bad practice. I suggest to take some time to learn about servlets.

Upvotes: 7

Related Questions