0

I'm using REST to POST (from Firefox's Poster) a url:

http://[ip]/page.jsp?paramater1=whatever&parameter2=whatever (Content Type: application/x-www-form-urlencoded)

The page.jsp contains:

<body onload="onload()">
<script>
    document.forms["myform"].submit(); // just to be redundant
    function onload(){
        document.forms["myform"].submit(); // just to be redundant
    }
</script>
<form action="SessionTestDriver" method="post" id="myform">
    [form stuff]
</form>

But it doesn't seem to be submitting that form. If I manually load the page on a browser, everything works perfectly. It's just the REST call that does nothing.

Clearly I'm missing something. Advice?

SOLVED! Got it! The main jsp page just called a servlet on submit. I tried that servlet directly in the REST url instead of the jsp page and everything worked how I wanted!

user2391981
  • 191
  • 1
  • 1
  • 5

2 Answers2

2

It sounds like you're making a request to a page that contains javascript, and you're concerned that the javascript on the requested page isn't running.

This is expected. When you request that page, the response is returned as a string, and that's it. The page isn't parsed, and javascript isn't evaluated. When you make an AJAX call, don't expect javascript in the page you're POSTing to to run.

(Sorry for explaining something so elementary if I've misunderstood your question.)

Trevor Dixon
  • 23,216
  • 12
  • 72
  • 109
  • No no, I'm at a pretty elementary level. I was under the impression that the javascript would be executed with a POST call. Thanks for the answer. That being said, is there some way that a javascript form submit can be executed from outside the webapp at all? – user2391981 Sep 13 '13 at 18:11
  • Do you control page.jsp? If so, you should change it to make a `POST` request using java instead of having javascript submit a form. Maybe http://stackoverflow.com/a/4206094/711902 will help. – Trevor Dixon Sep 13 '13 at 18:29
  • Got it! The main jsp page just called a servlet on submit. I tried that servlet directly in the REST url instead of the jsp page and everything worked how I wanted! – user2391981 Sep 13 '13 at 20:33
0

Not sure how HTML form and REST are being used, but you might want to make sure the document is loaded entirely first:

Try (if using jQuery)

<script>
    $(document).ready( function() { 
       $("#myform").submit();
    });
</script>
JGreenwood
  • 21
  • 1