submit form data to a new window failed using HTTP POST

Discussion in 'Java' started by Matt, Aug 23, 2004.

  1. Matt

    Matt Guest

    The following program submit a FORM DATA to a new window using HTTP
    POST,
    and postprocess.jsp couldn't get the form data. If I do in GET method
    and pass
    by query string in windowURL, then it works. But I need HTTP POST
    method,
    and I cannot use target="_blank" because I need to control the new
    window's
    properties (disable the scrollbars, menubars, etc...)

    Are there any workarounds?

    <html>
    <script type="text/javascript">
    function checkAndSubmitForm(theForm)
    {
    var windowURL = theForm.action;
    window.open(windowURL, "newWin",
    "scrollbars=0,menubar=0,toolbar=0,location=0,status=0");
    }
    </script>

    <body>
    <FORM NAME="formname" method="POST" action="postprocess.jsp">
    <P><input type=text" name="username"/>
    <P><input type="button" name="submitBtn" value="Submit Form"
    onClick="checkAndSubmitForm(document.formname)">
    </FORM>
    </body>
    </html>

    postprocess.jsp is just one line statement to get the form data
    <%= Request.Form() %>


    any ideas? please help!! thanks!!
     
    Matt, Aug 23, 2004
    #1
    1. Advertising

  2. Matt

    JScoobyCed Guest

    Matt wrote:

    > The following program submit a FORM DATA to a new window using HTTP
    > POST,
    > and postprocess.jsp couldn't get the form data. If I do in GET method
    > and pass
    > by query string in windowURL, then it works. But I need HTTP POST
    > method,
    > and I cannot use target="_blank" because I need to control the new
    > window's
    > properties (disable the scrollbars, menubars, etc...)
    >
    > Are there any workarounds?
    >
    > any ideas? please help!! thanks!!


    Hi,

    I would gladely help, but have not time right now. If you find
    anything please post the result here as I am interested.
    The only thing I could suggest is that when you POST a request, the
    connection is (I guess) "keep-Alive" and the result will be sent to the
    parent window. It's just my 2 cent comment and I wouldn't rely too much
    on it :)

    --
    JScoobyCed
    What about a JScooby snack Shaggy ? ... Shaggy ?!
     
    JScoobyCed, Aug 23, 2004
    #2
    1. Advertising

  3. Matt

    hiwa Guest

    (Matt) wrote in message news:<>...
    > The following program submit a FORM DATA to a new window using HTTP
    > POST,
    > and postprocess.jsp couldn't get the form data. If I do in GET method
    > and pass
    > by query string in windowURL, then it works. But I need HTTP POST
    > method,
    > and I cannot use target="_blank" because I need to control the new
    > window's
    > properties (disable the scrollbars, menubars, etc...)
    >
    > Are there any workarounds?
    >
    > <html>
    > <script type="text/javascript">
    > function checkAndSubmitForm(theForm)
    > {
    > var windowURL = theForm.action;
    > window.open(windowURL, "newWin",
    > "scrollbars=0,menubar=0,toolbar=0,location=0,status=0");
    > }
    > </script>
    >
    > <body>
    > <FORM NAME="formname" method="POST" action="postprocess.jsp">
    > <P><input type=text" name="username"/>
    > <P><input type="button" name="submitBtn" value="Submit Form"
    > onClick="checkAndSubmitForm(document.formname)">
    > </FORM>
    > </body>
    > </html>
    >
    > postprocess.jsp is just one line statement to get the form data
    > <%= Request.Form() %>

    I don't understand this.

    >
    >
    > any ideas? please help!! thanks!!
     
    hiwa, Aug 23, 2004
    #3
  4. Matt

    Grant Wagner Guest

    Matt wrote:

    > The following program submit a FORM DATA to a new window using HTTP
    > POST,
    > and postprocess.jsp couldn't get the form data. If I do in GET method
    > and pass
    > by query string in windowURL, then it works. But I need HTTP POST
    > method,
    > and I cannot use target="_blank" because I need to control the new
    > window's
    > properties (disable the scrollbars, menubars, etc...)
    >
    > Are there any workarounds?
    >
    > <html>
    > <script type="text/javascript">
    > function checkAndSubmitForm(theForm)
    > {
    > var windowURL = theForm.action;
    > window.open(windowURL, "newWin",
    > "scrollbars=0,menubar=0,toolbar=0,location=0,status=0");
    > }
    > </script>
    >
    > <body>
    > <FORM NAME="formname" method="POST" action="postprocess.jsp">
    > <P><input type=text" name="username"/>
    > <P><input type="button" name="submitBtn" value="Submit Form"
    > onClick="checkAndSubmitForm(document.formname)">
    > </FORM>
    > </body>
    > </html>
    >
    > postprocess.jsp is just one line statement to get the form data
    > <%= Request.Form() %>
    >
    > any ideas? please help!! thanks!!


    Yeah, no kidding you're not getting any data. You aren't EVER POSTing the
    <form> to the server. When the person clicks the button you retrieve the
    ACTION attribute of the <form> and use window.open() to do a GET of that
    page, passing no parameters. The ONLY way to POST the <form> to the
    server is to submit it (using either <input type="submit" ...> or
    document.forms['formName'].submit()).

    The solution to this is very simple:

    <form
    name="formname"
    method="POST"
    action="postprocess.jsp"
    target="postProcess"
    onsubmit="
    window.open(
    '',
    this.target,
    'scrollbars=0,menubar=0,toolbar=0,location=0,status=0'
    );
    return true;
    "
    >

    <!-- later in the page -->
    <input type="submit" name="submitBtn" value="Submit Form">

    (spread across multiple lines to avoid linewrapping)

    If JavaScript is enabled, the sequence of events is:
    1) the user activates the submit button
    2) the onsubmit event fires and starts (but may not finish) opening a new
    window with the same name as the TARGET attribute of the <form>
    3) the onsubmit event returns true to the event handler, which allows the
    <form> to continue submitting
    4) the <form> submits, following the TARGET attribute
    5) the browser detects that there is already a window with the same name
    as TARGET and targets the result of the form submission to that new
    window

    If JavaScript is disabled, the sequence of events is:
    1) the user activates the submit button
    2) the <form> submits, following the TARGET attribute
    3) the browser detects that there is window with the same name as TARGET
    and opens a new window to handle the rsult of the form submission

    In both cases, the form works regardless of whether the user has
    client-side JavaScript enabled, in both cases, the results of a form
    submission arrive in a new window so as not to "mess up" your current
    page. The only difference is, when client-side JavaScript is disabled you
    don't have control over the new window's chrome.

    Note that the TARGET attribute goes away in XHTML, and even today,
    several overly aggressive popup blockers may prevent the new window from
    opening, or may allow it to open or close it again immediately, providing
    no place to give the users feedback about their form submission.

    On the modern Internet, opening new windows is more and more discouraged.
    I'd suggest submitting the result of the form into the existing window,
    and then give the user navigation to return to the specific workflow.

    --
    Grant Wagner <>
     
    Grant Wagner, Aug 26, 2004
    #4
  5. Matt

    vivekvsingh

    Joined:
    Sep 14, 2006
    Messages:
    1
    Grant,

    I tried your method to do HTTP POST and open a new window. Using your suggested method:

    <form
    name="formname"
    method="POST"
    action="postprocess.jsp"
    target="postProcess"
    onsubmit="
    window.open(
    '',
    this.target,
    'scrollbars=0,menubar=0,toolbar=0,location=0,statu s=0'
    );
    return true;
    "
    >
    <!-- later in the page -->
    <input type="submit" name="submitBtn" value="Submit Form">


    It works perfectly for IE, but on Firefox it opens up two new windows. One new Window receives the response from the URL that I posted to , the other window remains blank.

    Any idea why that might be happening?

    Thanks in advance.

    Vivek
     
    vivekvsingh, Sep 14, 2006
    #5
    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. Matt
    Replies:
    7
    Views:
    5,388
    Isofarro
    Aug 27, 2004
  2. Replies:
    2
    Views:
    6,368
  3. Matt
    Replies:
    1
    Views:
    273
    Bob Barrows [MVP]
    Aug 23, 2004
  4. Matt
    Replies:
    1
    Views:
    236
  5. Replies:
    2
    Views:
    400
Loading...

Share This Page