Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > submit form data to a new window failed using HTTP POST

Reply
Thread Tools

submit form data to a new window failed using HTTP POST

 
 
Matt
Guest
Posts: n/a
 
      08-23-2004
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,statu s=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!!
 
Reply With Quote
 
 
 
 
JScoobyCed
Guest
Posts: n/a
 
      08-23-2004
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 ?!
 
Reply With Quote
 
 
 
 
hiwa
Guest
Posts: n/a
 
      08-23-2004
(Matt) wrote in message news:<. com>...
> 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,statu s=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!!

 
Reply With Quote
 
Grant Wagner
Guest
Posts: n/a
 
      08-26-2004
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,statu s=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,statu s=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 <>

 
Reply With Quote
 
vivekvsingh vivekvsingh is offline
Junior Member
Join Date: Sep 2006
Posts: 1
 
      09-14-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
submit the form data to the popup window without a submit button jrefactors@hotmail.com Javascript 2 01-01-2005 06:07 AM
submit the form data to the popup window without a submit button jrefactors@hotmail.com HTML 2 01-01-2005 06:07 AM
submit form data to a new window failed using HTTP POST Matt HTML 7 08-27-2004 09:53 PM
submit form data to a new window failed using HTTP POST Matt Javascript 1 08-23-2004 12:25 PM
submit form data to a new window failed using HTTP POST Matt ASP General 1 08-23-2004 10:48 AM



Advertisments