submit form data to a new window failed using HTTP POST

M

Matt

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!!
 
J

JScoobyCed

Matt said:
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 :)
 
H

hiwa

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.
 
G

Grant Wagner

Matt said:
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.
 
Joined
Sep 14, 2006
Messages
1
Reaction score
0
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
 

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,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top