need to connect to a server through a URL using response.sendRedirect()

P

padalaprashant

Any one please solve the problem below.....

I need to connect to a server through a URL for 10 time using
response.sendRedirect() is it possible??

I am a lay man in java, just a beginner in java, i got a problem when
i am connecting to a web site say www.google.com my code goes as
follows
<%
for(int i = 0; i < 10;i++){
response.sendRedirect("http://www.google.com");
}
%>
can i write code like this??
 
M

Marcelo Morales

Try to be clear. I don't understand what you are trying to accomplish,
but I will give some pointers anyway.

It seems like you are using JSP. Therefore, I assume you are running
it inside a servlet container like tomcat, and that there is a browser
consuming the JSP via HTTP. Even if you pull this off, i.e. manage to
send ten redirects to a web client (and I am not saying it is even
legal or possible), there is no way a web client will make ten
different requests.
 
R

Roger Lindsjö

padalaprashant said:
Any one please solve the problem below.....

I need to connect to a server through a URL for 10 time using
response.sendRedirect() is it possible??

What do you mean? You can only send one redirect per request, once the
redirect is sent the client will (probably) follow the redirect.

What would you expect from sending a redirect multiple times? Could you
explain what you want solved instead of what you are implementing?
I am a lay man in java, just a beginner in java, i got a problem when
i am connecting to a web site say www.google.com my code goes as
follows
<%
for(int i = 0; i < 10;i++){
response.sendRedirect("http://www.google.com");
}
%>
can i write code like this??

Nope, the javadoc says:
"After using this method, the response should be considered to be
committed and should not be written to."

So calling sendRedirect multiple times could trigger an
IllegalStateException.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top