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

Discussion in 'Java' started by padalaprashant, Mar 5, 2008.

  1. 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??
    padalaprashant, Mar 5, 2008
    #1
    1. Advertising

  2. Re: need to connect to a server through a URL usingresponse.sendRedirect()

    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.

    On Mar 5, 7:35 am, padalaprashant <> wrote:
    > 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 saywww.google.commy code goes as
    > follows
    > <%
    > for(int i = 0; i < 10;i++){
    > response.sendRedirect("http://www.google.com");}
    >
    > %>
    > can i write code like this??
    Marcelo Morales, Mar 5, 2008
    #2
    1. Advertising

  3. padalaprashant wrote:
    > 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.

    --
    Roger Lindsjö
    Roger Lindsjö, Mar 5, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas
    Replies:
    6
    Views:
    3,205
    Andrea Desole
    Feb 15, 2005
  2. carlisle411
    Replies:
    4
    Views:
    12,272
    John C. Bollinger
    Feb 28, 2005
  3. Jeano
    Replies:
    5
    Views:
    7,231
    Orilg
    Oct 13, 2010
  4. ohaya
    Replies:
    0
    Views:
    4,078
    ohaya
    Jun 30, 2005
  5. Replies:
    1
    Views:
    805
    chris brat
    Jun 2, 2006
Loading...

Share This Page