Can't send POST data from servlet

Hi,
I have a servlet that receives data via GET method, process the request and then it has to send feedback to an url, but the query string that
I have to send must be in a POST method.
I ilustrate this:
http://host:port/myservlet?param1=value1
myservlet proccess and then calls
http://external_url (with param2=value2 via POST)
I've tried to put an HttpURLConnection
URL url = new URL("http://localhost:7001/prueba.jsp");
java.net.HttpURLConnection con= (HttpURLConnection)url.openConnection();
//POST data
URL url = new URL("http://localhost:7001/prueba.jsp");
HttpURLConnection c = (HttpURLConnection)(url.openConnection());
c.setDoOutput(true);
PrintWriter out = new PrintWriter(c.getOutputStream());
out.println("param2=" + URLEncoder.encode("value2"));
out.close();
but I get this error.
lun mar 10 13:53:46 GMT+01:00 2003:<W> <ListenThread> Connection rejected: 'Login timed out after 5000 msec. The socket
came from [host=127.0.0.1,port=2184,localport=7001] See property weblogic.login.readTimeoutMillis to increase of decreas
e timeout. See property weblogic.login.logAllReadTimeouts to turn off these log messages.'
(it's a weblogic 5.1 problem, i've been researching a little bit)
And I don't want to call a jsp that generates a post form, and then it's auto-submitted with javascript. (this will be the last remedy!!)
How can i do this?
All suggestions will be grateful.
Thanks in advance.
PD: sorry for my english :)

I make an URLConnection and I intended to know if the post data was
sent right. Then, in my machine, under weblogic 5.1, I developed a jsp with this code:
<%
URL url = new URL("http://machine2/examples/prueba.jsp");
HttpURLConnection c = (HttpURLConnection)(url.openConnection());
c.setDoOutput(true);
PrintWriter outd = new PrintWriter(c.getOutputStream());
outd.println("param1=" + URLEncoder.encode("value1"));
outd.close();
c.disconnect();
%>
and in machine2 (using tomcat 4.1), I simply put a line in prueba.jsp:
System.out.println(request.getParameter("param1"));
and I don't get "value1" in the tomcat log as expected (I think).
I also tried with adding this properties:
c.setRequestProperty("Content-Length", size...);
c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
and it didn't work!
what's wrong?

Similar Messages

  • How can i send the data from WD to SMARTFROMS to fill it?

    Hi All,
    how can i send the data from WD to SMARTFROMS to fill it?
    Best Regards

    Hello
    After conferring with a colleague, the following response may help:
    The Smart Form doesn't have any special integration in WebDynpro.
    Therefore the application should implement it especially.
    Steps:
    1) Call of Smart Forms in mode GET_OTF
    2) Convert OTF to PDF
         3) Show the PDF in WD Context Node
    Similar topic was discussed here:
    Re: Displaying Smartforms in Webdynpro ABAP
    Thanks
    Kind Regards
    Toros Aledjian
    Edited by: Toros Aledjian on Nov 29, 2010 8:43 AM

  • How can I send registeration data from Mac machine to NT machine?

    How can i send or post data from Mac machine to NT machine without using browser? I m stucked. I want to register a customer from Mac machine by a container i.e. Form having awt components etc. and send it to NT machine to trigger it into SQL Server. Can i use Servlet for this purpose? The problem is client machine have Mac and no browser. But host machine is NT based.

    Thanks !
    I have got that one. But its documentation API describes very little information. I could not properly follow. if there is some help to start up in HTTP client?
    Can i use classes of HTTP client in my application and why i need it, I m not following as well. Please describe reply in detail.

  • How can I send post data through nsurlrequest?

    Hi.
    I'm working on an application which needs to make requests to a php gateway. I tried many examples I found on google, but none of them worked for me.
    First I was working with GET, and it worked just fine, but now, as I need to send more complex data, GET isn't a solution anymore. I have three params to send: module which is a string containing a php class name, method: the function in the class, and params for the function which is usually an indexed array.
    The following method makes the request to the server, but for some reason, doesn't send the POST data. If I var_dump($_REQUEST) or var_dump($_POST), it turns out, the array is empty. Can somebody tell me, what am I doing wrong? Is there some kind of a sandbox, which prevents data from being sent to the? I also tried to send some random strings, which aren't json encoded, no luck. The sdk version is 5.1, and I'm using the iPhone simulator from xcode.
    If it is possible I would like to solve this problem without any additional libraries (like asihttp).
    And here is the code:
    +(NSObject *)createRequest:(NSString *)module: (NSString *)method: (NSArray *)params
        NSString *url       = @"http://url/gateway.php";
        NSData *requestData = nil;
        NSDictionary *data  = [NSDictionary dictionaryWithObjectsAndKeys:
                module, @"module",
                method, @"method",
                params, @"params",
                nil];
        NSString *jsonMessage = [data JSONRepresentation];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
        NSString *msgLength = [NSString stringWithFormat:@"%d", [jsonMessage length]];
        [request addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
        [request addValue: msgLength forHTTPHeaderField:@"Content-Length"];
        [request setHTTPMethod:@"POST"];
        [request setHTTPBody: [jsonMessage dataUsingEncoding:NSUTF8StringEncoding]];
        requestData     = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        NSString *get   = [[NSString alloc] initWithData:requestData encoding:NSUTF8StringEncoding];
        NSLog(@">>>>>>%@<<<<<<",get);
    Thank you.

    raczzoli wrote:
    I'm working on an application which needs to make requests to a php gateway. I tried many examples I found on google, but none of them worked for me.
    Why not?
    Unfortunately, you are dealing with a number of different technologies that have been cobbled together over the years. You could write a PHP server that would respond correctly to this request, but not using basic methods like the $_POST variable. PHP was designed for HTML and true forms. What you are trying to do is make it work as a general purpose web service over the HTTP protocol. You can do that, but not with the form-centric convenience variables.
    The following is a basic program that will populate the $_POST variable.
    #import <Foundation/Foundation.h>
    int main(int argc, const char * argv[])
      @autoreleasepool
        // insert code here...
        NSLog(@"Hello, World!");
        NSString  * module = @"coolmodule";
        NSString * method = @"slickmethod";
        //NSArray * params = @[@"The", @"Quick", @"Brown", @"Fox"];
        NSString * params = @"TheQuickBrownFox";
        NSString * url = @"http://localhost/~jdaniel/test.php";
        NSDictionary * data  =
          [NSDictionary
            dictionaryWithObjectsAndKeys:
              module, @"module",
              method, @"method",
              params, @"params",
              nil];
        //NSString *jsonMessage = [data JSONRepresentation];
        //NSData * jsonMessage =
        //  [NSJSONSerialization
        //    dataWithJSONObject: data options: 0 error: nil];
        NSMutableArray * content = [NSMutableArray array];
        for(NSString * key in data)
          [content
            addObject: [NSString stringWithFormat: @"%@=%@", key, data[key]]];
        NSString * body = [content componentsJoinedByString: @"&"];
        NSData * bodyData = [body dataUsingEncoding: NSUTF8StringEncoding];
        NSMutableURLRequest * request =
          [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:url]];
        //NSString * msgLength =
        //  [NSString stringWithFormat: @"%ld", [jsonMessage length]];
        NSString * msgLength =
          [NSString stringWithFormat: @"%ld", [bodyData length]];
        [request
          addValue: @"application/x-www-form-urlencoded; charset=utf-8"
          forHTTPHeaderField: @"Content-Type"];
        [request addValue: msgLength forHTTPHeaderField: @"Content-Length"];
        [request setHTTPMethod: @"POST"];
        //[request setHTTPBody: jsonMessage];
        [request setHTTPBody: bodyData];
        NSData * requestData =
          [NSURLConnection
            sendSynchronousRequest: request returningResponse: nil error: nil];
        NSString * get =
          [[NSString alloc]
            initWithData: requestData encoding: NSUTF8StringEncoding];
        NSLog(@">%@<",get);
      return 0;
    I have written this type of low-level server in PHP using the Zend framework. I don't know how to do it in basic PHP and wouldn't bother to learn.
    Also, you should review how you are sending data. I changed your example to send the appropriate data and content-type for the $_POST variable. If you had a server that could support something else, you could use either JSON or XML, but your data and content-type would have to match.

  • Send POST data from custom POD to PHP server

    Hi all,
    I tried to send data from custom POD to PHP server with POST method. I used HTTPService component and URLLoader, but nothing happend. All attempts failed, HTTPService return "fault" and URLLoader return "0" that means I can't send data to the server.
    I'm googling around during few hours... please give me some advice, how I can send data from custom POD to PHP server.
    Thanks

    Figured it out, hope it will help someone
    A bit tricky but it works fine, now I can send and retrive data from PHP server.
    Add .htacces file in folder where deployed PHP request handler and modify it, see below:
    RewriteEngine on
    RewriteBase /foldername
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)\?*$ filename.php?_route_=$1 [L,QSA]
    Thanks

  • Can i send cloab data from UTL SMTP WRITE RAW DATA?

    hi
    here is my code to send email from oracle as attachment using demomail package provided by oracle----
    create or replace procedure html_mail(
    p_sender varchar2, -- sender, example: 'Me <[email protected]>'
    p_recipients varchar2, -- recipients, example: 'Someone <[email protected]>'
    p_subject varchar2, -- subject
    p_text varchar2, -- text
    p_filename varchar2, -- name of html file
    p_blob blob -- html file
    ) is
    conn utl_smtp.connection;
    i number;
    len number;
    BEGIN
    conn := demo_mail.begin_mail(
    sender => p_sender,
    recipients => p_recipients,
    subject => p_subject,
    mime_type => demo_mail.MULTIPART_MIME_TYPE);
    demo_mail.begin_attachment(
    conn => conn,
    mime_type => 'application/csv',
    inline => TRUE,
    filename => p_filename,
    transfer_enc => 'base64');
    -- split the Base64 encoded attachment into multiple lines
    i := 1;
    len := DBMS_LOB.getLength(p_blob);
    WHILE (i < len) LOOP
    IF(i + demo_mail.MAX_BASE64_LINE_WIDTH < len)THEN
    UTL_SMTP.Write_Raw_Data (conn
    , UTL_ENCODE.Base64_Encode(
    DBMS_LOB.Substr(p_blob, demo_mail.MAX_BASE64_LINE_WIDTH, i)));
    ELSE
    UTL_SMTP.Write_Raw_Data (conn
    , UTL_ENCODE.Base64_Encode(
    DBMS_LOB.Substr(p_blob, (len - i)+1, i)));
    END IF;
    UTL_SMTP.Write_Data(conn, UTL_TCP.CRLF);
    i := i + demo_mail.MAX_BASE64_LINE_WIDTH;
    END LOOP;
    demo_mail.end_attachment(conn => conn);
    demo_mail.attach_text(
    conn => conn,
    data => p_text,
    mime_type => 'text/csv');
    demo_mail.end_mail( conn => conn );
    END;
    Above i m using
    p_blob blob -----to send message as attachment now i have table containg data into clob format nw if i send it as it is just changing coulmn from Pblob--- Clob
    then it gives me error at UTL SMTP WRITE RAW DATA...
    for that i do wrkaround as i m taking data from table as clob convert it to blob and
    send as attachment ...
    can any one guide me little that is this approcah proper?do i really need to convert data from clob to blob?
    bcause in 10g Mail UTL_MAIL raw attachment i have limitation on size of email.attachment........

    > still no email comes. No error as well.
    SMTP itself is straight forward. It is a delivery protocol. And very easy to implement. Which is what UTL_SMTP does - without bugs or errors (none to my knowledge and experience using UTL_SMTP extensively for a long time now).
    The problems experience are 50% of the time, incorrectly using SMTP. The other 50% of the time, incorrectly constructing a Mime Internet Message Body for SMTP to deliver. Both are issues that the caller (app code using UTL_SMTP) needs to address.
    As UTL_SMTP is program-driven, it is not that easy to play with and debug the conversation with the SMTP server - and figure out just what the SMTP server expects, not like, disallows, etc.
    In order to make sure that you are having a proper/valid conversation with the SMTP server, do it interactively using a telnet session on the Oracle server platform. All you do with telnet is to send the very same PL/SQL coded SMTP commands and parameters to the SMTP server - but interactively.
    E.g.
    /home/billy> telnet mail 25
    Trying 165.143.128.194...
    Connected to mail
    Escape character is '^]'.
    220 mail Tue, 13 May 2008 11:20:59 +0200
    HELO 10.251.93.58
    250 mail: Hello [10.251.93.58]
    MAIL FROM:<[email protected]>
    250 <[email protected]>: Sender Ok
    RCPT TO:<[email protected]>
    250 <[email protected]>: Recipient Ok
    DATA
    354 mail: Send data now. Terminate with "."
    Subject: Test Message
    This is a test e-mail.
    250 mail: Message accepted for delivery
    QUIT
    221 mail closing connection. Goodbye!
    Connection closed by foreign host.
    /home/billy>
    Simply substitute the SMTP parameters you use in your PL/SQL calls to UTL_SMTP above. And use the same SMTP command sequence as you do in your code.
    Note that in the above case, the SMTP server quite happily accepted incorrect and undeliverable sender and recipient addresses. Which means that the e-mail will wind up in the Big Bit Bucket In The Sky. No errors.

  • Exception sending serialised data from servlet to applet

    Hello,
    I have a servlet that sends periodically a serialised object to an applet, under a http get request. it works fine, but if I force the comunication not waiting too much between requests, I am getting this anoying exception:
    java.io.StreamCorruptedException:EOFException while reading stream header
    This is a piece of code:
    SERVLET--------
    (called within the doGet)
    public void sendSerialisedData(HttpServletResponse response, PlatformData dataToSend)
    ObjectOutputStream outputToApplet;
    try
    outputToApplet = new ObjectOutputStream(response.getOutputStream());
    response.setContentType("application/x-java-serialized-object");
    outputToApplet.writeObject(dataToSend);
    outputToApplet.flush();
    outputToApplet.close();
    catch (IOException e)
    e.printStackTrace();
    APPLET--------
    HttpURLConnection servletConnection = (HttpURLConnection)url.openConnection();
    servletConnection.setDoOutput(false);
    servletConnection.setDoInput(true);
    servletConnection.setRequestMethod("GET");
    servletConnection.setUseCaches(false);
    servletConnection.setDefaultUseCaches(false);
    servletConnection.setRequestProperty("Content-type","application/x-java-serialized-object");
    ObjectInputStream inputToServlet = new ObjectInputStream(servletConnection.getInputStream());
    setTheData( (PlatformData) inputToServlet.readObject());
    inputToServlet.close();
    servletConnection=null;
    The method that receives the refresh petitions in the client is synchronized, that means that I have ensured that no petition will be processed until the method on charge of processing it has finished.
    I have spent 3 days with this problem, but I have not been lucky. Does anyone have an idea of what is happening?
    thank you very much
    carlos
    [email protected]

    the
    communication works fine until you force a more
    frequent communication... Ok.
    I had a similar problem a while back while implementing an applet-servlet pipeline. I remember solving it by writing the objs in byte arrays and sending the byte arrays instead. The only other difference is that I was using POST instead of GET.
    In your servlet :
    // first
    con.setRequestProperty("Content-type","application/octet-stream");
    // method
    private byte[] convertObjectToByteArray( Object obj ) throws IOException
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream( b );
    out.writeObject( obj );
    return b.toByteArray();
    // code
    byte[] b = convertObjectToByteArray( obj );
    ObjectOutputStream out = new ObjectOutputStream( resp.getOutputStream() );
    out.writeObject( b );
    out.close();And in your applet, get the byte array and convert that to objects.:
    // method
    private Object convertByteArrayToObject( byte[] b ) throws Exception
    ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream&#10149;
    ( b ) );
    return in.readObject();
    // code
    ObjectInputStream in = new ObjectInputStream( con.getInputStream() );
    byte[] b = (byte[])in.readObject();
    in.close();
    // then call convertByteArrayToObject( b );If the above does not make a difference, I'm afraid I can't be of further help...

  • How can we post data from CRM to SAP using ABAP proxies???

    Hi ,
      Can anyone hep me to create interface for the following scenario How can we post data from CRM to SAP using ABAP proxies???, can I find any document ???????
    Thanks in advance
    Andy

    Andy,
    Please look at these weblogs.
    /people/ravikumar.allampallam/blog/2005/03/14/abap-proxies-in-xiclient-proxy
    /people/ravikumar.allampallam/blog/2005/03/03/creating-purchase-order-idoc-through-xi
    /people/siva.maranani/blog/2005/04/03/abap-server-proxies
    /people/vijaya.kumari2/blog/2006/01/26/how-do-you-activate-abap-proxies
    These should give a good idea about implementing Proxies.
    Regards,
    Ravi

  • Can we send the data into different data target from single datasource how

    Hai
    can we send the data into different data target from single datasource how ?

    Hi,
    Create the transformation for each target and connect through DTP if you are in BI 7.0
    If it is BW 3.5 create transfer rules and load it Info source and then different update rules for different targets then load it using IP.
    If you are speaking about loading data from R3 data source to multiple data sources in BI
    Then follow the below step.
    1)create init IP's and run the IP's with different selection to different DSO(With same selection it is not possible).
    2)Then you will have different delta queues for the same data source in RSA7
    3)Your delta loads will run fine to different data sources from same DS in R3.
    Hope this helps
    Regards,
    Venkatesh

  • Error while posting data from SCM to XI

    Dear Expertise,
    I got a requirement where I need to post data from SCM to XI server. From SCM
    side it is an ABAP proxy. When I tested the scenario and checked in the MONI of
    SCM I got an error. But SCM is correctly configured pointing to XI under Tcode
    SM59 (SM59 --> Connection Type H (HTTP Connection to ABAP System) -->with
    correct user credentials and PIPE line URL of XI server).
    Please let me know is this the correct settings for ABAP proxy for connecting
    from SCM system to XI system.
    Error Dump in SXMB_MONI:
      <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Call Integration Server
      -->
    - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
      <SAP:Category>XIServer</SAP:Category>
      <SAP:Code area="INTERNAL">HTTP_RESP_STATUS_CODE_NOT_OK</SAP:Code>
      <SAP:P1>401</SAP:P1>
      <SAP:P2>Unauthorized</SAP:P2>
      <SAP:P3 />
      <SAP:P4 />
    <SAP:AdditionalText><!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01Transitional//EN">
      <SAP:ApplicationFaultMessage namespace="" />
      <SAP:Stack>HTTP response contains status code 401 with the description Unauthorized Authorization error while sending by HTTP (error code: 401, error text: Unauthorized)</SAP:Stack>
      <SAP:Retry>M</SAP:Retry>
      </SAP:Error>
    Thanks in Advance,
    Gujjeti

    HI
    Check these
    For Error: HTTP_RESP_STATUS_CODE_NOT_OK 401 Unauthorized
    Description: The request requires user authentication
    Possible Tips:
    • Check XIAPPLUSER is having this Role -SAP_XI_APPL_SERV_USER
    • If the error is in XI Adapter, then your port entry should J2EE port 5<System no>
    • If the error is in Adapter Engine
    –then have a look into SAP note- 821026, Delete the Adapter Engine cache in transaction SXI_CACHE Goto --> Cache.
    • May be wrong password for user XIISUSER
    • May be wrong password for user XIAFUSER
    – for this Check the Exchange Profile and transaction SU01, try to reset the password -Restart the J2EE Engine to activate changes in the Exchange Profile After doing this, you can restart the message

  • Need to POST data from a desktop client to a server.

    Hello all, it's been awhile since I've posted here, so I hope everyone has been doing well.
    I have cross posted this here java - Need to POST data from a client application to my server - Stack Overflow but no answers, and since SO has been extremely slow for the questions I've been asking I am posting here.
    Here is the post:
    I know the title is probably a common question, but I am a bit confused on everything I'm trying to do, so I am trying to piece it together, and figured a common title would be better than a confusing one.
    I am basically developing a web application and one part of that is a file uploader. I am using Apache Commons File Upload via the Streaming API, and that all works fine, except I need to access the file I'm uploading, because that contains data to additional files to upload.  I.e., Read File A, get paths to images, upload images with File A to server and save on server.  The API can be found here http://commons.apache.org/proper/commons-fileupload/streaming.html
    I was told there is a security risk via the web and would be impossible via a browser, since the user needs to select all files to upload, i cannot tell the browser to upload additional files, so I am left with a client side option.
    I am confused if there is a special library I need, or as I have been seeing threads that talk about using the built in UrlConnection Class or http://hc.apache.org/
    I basically need to be able to read the file, which technically gives me a path to a Database on the user's system which I then read to get the additional images.  After I get all of that I then  need to post the data as a multipart form as that is what the FileUpload requires.
    form method="POST" enctype="multipart/form-data" action="fup.cgi">
      File to upload: <input type="file" name="upfile"><br/>
      Notes about the file: <input type="text" name="note"><br/>
      <br/>
      <input type="submit" value="Press"> to upload the file!
    </form>
    This is the example found in the Overview section of the Fileupload which can be accessed from the link above.
    There wouldn't be an issue if the users uploaded all of the data themselves, but since I have to do some of it automatically it causes some "concerns/issues."
    Basically these files are created and packaged from another application, so the images, and the db will always be in the same place, and that file that they are uploading is a file the other program creates, so everything will always be known, I just need to upload it, and then POST it as enctype="multipart/form-data" So that my servlet can read it and save it on my server.
    So I would appreciate it if anyone had any suggestions on where to begin my journey with this.  I have heard of a few applications like curl and wget that are used for this, but those seem to be more C based.  As mentioned earlier it seeems the httpcomponets from apache might work well, but I want to make sure.
    I appreciate all the help, thank you for your time all.

    It's not possible to read from a file without using classes from the core API*. You'll have to get clarification from your instructor as to which classes are and are not allowed.
    [http://java.sun.com/docs/books/tutorial/essential/io/]
    *Unless you write a bunch of JNI code to replicate what the java.io classes are doing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Send form data from Coldfusion to ASP

    I need to send form data from CF to ASP.
    I submit a CF page and validate it on my end with another CF
    page, which then needs to post the results to an asp page on
    another site. The post has to be sent via SSL and I don't need to
    and cannot receive any status message back from the remote ASP
    site. Any suggestions would be greatly appreciated. I was thinking
    some type of cfhttp, but I am not very familiar with its usage.
    Thanks!

    It doesn't matter what type of page you are sending to as
    long as it can handle the data that is sent. Either a form or
    cfhttp will work.

  • Sending post data to remote site

    I would normally use CURL and php to do this but I was wanting to see if i can use flex to send the post data, I am making an app which sends post data to another site, and was wanting to know the best way of doing this in flex..

    ok cool, I basically need to be able to prepopulate any form from any website and submit it, even if the site doesn't have an API.
    the sites I am submiting to all have API's but I thought it would be better this way because API's change alot.

  • Pass data from servlet to jsp using sendRedirect

    Hi,
    I am passing data from servlet to jsp using forward method of request dispatcher but as it doesn't change the url it is creating problems. When ever user refreshes the screen(browser refresh) it's re-loading both servlet and jsp, which i don't want to happen. I want only the jsp to be reloaded.
    Can I pass data from servlet to jsp using sendRedirect in this case. I also want to pass some values from servlet to jsp but without using query string. I want to set some attributes and send to jsp just like we do for forward method of request dispatcher.
    Is there any way i can send data using attributes(without using query string) using sendRedirect? Please let me know

    sendRedirect is meant as a true redirect. meaning
    you can use it to redirect to urls not in your
    context....with forward you couldn't pass information
    to jsps/servlets outside your own context.Actually, you can:
    getServletContext().getContext("/other").getRequestDispatcher("/path/to/servlet").forward(request, response)I think the issue here is that the OP would like to have RequestDispatcher.forward() also update the address in the client's browser. That's not possible, AFAIK. By the time the request is forwarded, the browser has already determined the URL of the servlet, and the only I know of way to have the browser change the URL to the forwarded Servlet/JSP is to send a Location: header (i.e. sendRedirect()). Remember that server-side dispatching is transparent to the client. Maybe there's some tricky stuff you can do with JavaScript to change the address in the address bar without reloading the page?
    Brian

  • Exchange POST data between servlets?

    Hello all
    First of all, my apologies for my English. This is the first time writing to forum.
    I�m new to java and I need a little help with servlets.
    I have the servlets A, B and C.
    Servlet A just display a page with a form tag witch send the data to Servlet C via POST method. What I want is to intercede the Servlet B between them and check the integrity of those POST data.
    For example: Servlet A send data to Servlet B via POST method, Servlet B check the integrity of those data, and finally Servlet B send those data to Servlet C via POST method.
    For now the only I have done is to send the data to B and transfer the data to C with GET method.
    How can I send data with POST method in a servlet?
    The code so far:
         String urlstr = new String();
         String str1 = request.getParameter("st_name");
    String str2 = request.getParameter("st_birth");
    String str3 = request.getParameter("st_class");
    ��some check ����
         urlstr = "/student/check_st?st_name=" + str1 + "&st_birth=" + str2 + "&st_class=" + str3;
         response.sendRedirect(urlstr);
    Thanks in advanced.
    Ilias

    You should use the RequestDispatcher.forward(request,response) method.
    For example, inside Servlet B do this:
    public void doPost(ServletRequest request, ServletResponse response) {
        ... validate parameters ...
        RequestDispatcher dispatcher = request.getRequestDisplatcher("ServletC");
        dispatcher.forward(request,response);
    }This prevents an extra request-response cycle to the client and between the .forward() and .include() methods of the RequestDispatcher, should be considered the preferred way of server-side redirection unless there is a specific need to go to the client first.
    See the J2EE API:
    http://java.sun.com/javaee/5/docs/api/

Maybe you are looking for