This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes trying to submit form on another site from my JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "trying to submit form on another site from my JSP" Watch "trying to submit form on another site from my JSP" New topic
Author

trying to submit form on another site from my JSP

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Okay, hopefully I won't get in trouble for showing all this...below is the code for what I'm trying to do, and it's not submitting to the form mentioned (it just seems to do nothing). Maybe you can try to get it to work and let me know the workaround. Above what I'm pasting below is my Java code within JSP's <% %> tags. I'm using the IntelliJ Idea IDE and although I'm not compiling with it, it's not complaining about any imports needed or anything like that (it's good at doing that at editing time). If you try this yourself, don't worry about submitting the form at the site, b/c after that there's a confirmation page before you fully submit. Btw, I've tried it both with and without quote marks around the field name.
<html>
<body>
<form name="SAPF" method="POST" action="http://sbw.airborne.com/SchedulePickup/SchedulePickupInfo.asp">
<input type=hidden name=F10050 value="08222003">
<input type=hidden name=F10051 value="1200">
<input type=hidden name=F10052 value="1700">
<input type=hidden name=F10055 value="1">
<input type=hidden name=F10026 value="<%=oBill.getCompanyName()%>">
<input type=hidden name=F10027 value="<%=oBill.getAddress1()%>">
<input type=hidden name=F10028 value="<%=oBill.getAddress2()%>">
<input type=hidden name=F10029 value="<%=oBill.getCity()%>">
<input type=hidden name=F10030 value="<%=oBill.getState()%>">
<input type=hidden name=F10031 value="<%=oBill.getZip()%>">
<input type=hidden name=F10018 value="<%=oBill.getAttn()%>">
<input type=hidden name=F10025 value="<%=oBill.getShipperPhone()%>">
</form>
I learned to do this from here:
http://forum.java.sun.com/thread.jsp?forum=45&thread=436406&tstart=0&trange=15
[ August 21, 2003: Message edited by: Stephen Huey ]
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476

...below is the code for what I'm trying to do, and it's not submitting to the form mentioned (it just seems to do nothing).

When you say this, do you mean when you submit the form nothing happens meaning even in status bar there is no indicator of page being loaded, or do you mean that browser just sits there like nothing is going on?
Alex
[ August 21, 2003: Message edited by: Alex Kravets ]

All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Also, I trust that in your actual form you have a submit button.
[ August 21, 2003: Message edited by: Alex Kravets ]
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
My actual form has no submit button, and it doesn't appear to need one, either. When my users click the link to my form page, the form on my page seems to auto-submit itself with that Javascript at the bottom. Then (after a split second), it takes me to the URL in question, but when it gets there, it looks just the way it does when you load that page normally. I would know if there were errors in submission or if incomplete information was being submitted, b/c their page (the Airborne one) comes back and tells you that you missed some info or whatever. So, what I'm wondering is if I have to do some more involved coding to POST some info to that form or what...also, am I specifying everything I need to? For example, when I give it that URL to submit to, do I need to somehow tell it WHICH form on that page to submit to, or does it do that automatically? I'm wondering how it would know if there were multiple forms on that page...
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
can you post javascript that submits the page?
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Whoops, sorry about that--here's the complete code:
<html>
<body>
<form name="SAPF" method="POST" action="http://sbw.airborne.com/SchedulePickup/SchedulePickupInfo.asp">
<input type=hidden name="F10050" value="08222003">
<input type=hidden name="F10051" value="1200">
<input type=hidden name="F10052" value="1700">
<input type=hidden name="F10055" value="1">
<input type=hidden name="F10026" value="<%=oBill.getCompanyName()%>">
<input type=hidden name="F10027" value="<%=oBill.getAddress1()%>">
<input type=hidden name="F10028" value="<%=oBill.getAddress2()%>">
<input type=hidden name="F10029" value="<%=oBill.getCity()%>">
<input type=hidden name="F10030" value="<%=oBill.getState()%>">
<input type=hidden name="F10031" value="<%=oBill.getZip()%>">
<input type=hidden name="F10018" value="<%=oBill.getAttn()%>">
<input type=hidden name="F10025" value="<%=oBill.getShipperPhone()%>">
</form>

<script language="Javascript">
document.SAPF.submit();
</script>
</body>
</html
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
It's kind of hard to follow when there is no complete code. But I guess the link that you mentioned where a user clicks must have some kind of javascript property that performs the actual submition.
Also on you action page (which seems to be ASP page) how do you receive your hidden parameters?
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
No, the link my users follow to get to the above page is a simple hyperlink with a relative URL to the name of the page. Nothing fancy there. What happens is, when the page above gets loaded, that simple little Javascript statement (that I picked up from a guy in a Sun forum, as I mentioned at the top of this thread) at the bottom of my code auto-submits the form on the page as soon as the page is loaded (so that I see the page for only a split second before it loads the Airborne page in the browser). Because I then see the Airborne page in the browser, I feel I can safely assume that it submitted my form, b/c the form action attribute is the only place I tell it anything about that Airborne page.
Now, I don't have any control over Airborne's ASP page. I can't see any more of the ASP code than you can. Although I'd like to be able to automatically submit it from within my code, all I can do right now is go to it in a web browser, type some stuff in, and submit it to see either a confirmation page, or the same page telling me that I entered some errors. You can easily mimic what I'm trying to do by creating a simple HTML page with the following text:

In other words, the above should be complete code. Notice that I took out the fields whose values were coming from my Java/JSP code and just left the ones that were hardcoded text values. That part shouldn't matter here. If there were an error with that part, then I would've expected the page I'm submitting to to tell me that there were errors with the data I was entering. But I can't even get that page I'm submitting to to even submit! I'm trying to POST to it, and that doesn't seem to be working. Look at the source on that Airborne page and you can see the name of the form there--am I supposed to somehow tack that form name onto the URL above to specify WHICH form I'm posting to, or do I not need to do that?
Now, if you can get the above to actually submit, then I'd expect to see warnings in red text telling me that I didn't fill in all the fields. That would be heavenly to see. I just don't know why I'm not seeing that!
Thanks,
Stephen
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Yup, I see what you are saying. I tried to submit to the ASP page with:
http://sbw.airborne.com/SchedulePickup/SchedulePickupInfo.asp?F10052=1700 thinking that drop-down box 'Time your business closes' will display 5:00pm but it does not. I wonder how ASP page reads input parameters from the url?
[ August 21, 2003: Message edited by: Alex Kravets ]
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
I don't think that will work simply b/c in the HTML source for the page, you can see that each field's value is hardcoded like this:
value=""
So, it *seems* like a POST might get past that problem, but I don't even know for sure...
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
Well the way I deal with drop-down boxes in my JSP page is by going thru value of drop-down box and comparing them to what I got from url. If they match I put selected next to the value of drop-down box and build drop-down box like that. Not sure what's going on in ASP.
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
You are trying to post the values to the page that the user uses to enter them. You should be submitting them to the page that IT submits them to:
http://sbw.airborne.com/SchedulePickup/SchedulePickupInfo.asp?nav=
Then you'll be fine!
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
Thanks--I'm nuts! I figured that out right at the end of the work day.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: trying to submit form on another site from my JSP