Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect to a different url

Tags:

java

jsp

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?

like image 209
sujit Avatar asked Dec 01 '25 10:12

sujit


1 Answers

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.

like image 94
BalusC Avatar answered Dec 03 '25 00:12

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!