How to load correct page after a POST received - using HTTPServer
homosapien
Posts: 147
New to the Spinneret and HTML, looks like a great tool.
Mike G. - excellent info on your site for getting started with web work and the Spinneret - thank you. Have already started acquiring books on HTML and internet protocols after examining your tutorials and spinneret code.
My question: I am using a slightly modified version of HTTPServer. In my application, the server(Spinneret) sends a form to a browser and the browser user responds by filling out input fields and hitting a 'submit' button and the server gets the POST response. Is there a 'clean' way to have the server send a page back to the browser after receiving the POST response (so the user sees something other than the input form)?
I am thinking I could use the Request.setName method (and other SET methods from Request.spin as needed) to alter the POST response header (after processing the needed input form data) and call the staticFileHandler method, but this seems kind of kludgy.
Am I missing something obvious here?
If this question is too vague or not enough info, please let me know. Not trying to be abstruse, beginner HTML/Spinneret/HTTPServer here....
Thanks,
Nate
Mike G. - excellent info on your site for getting started with web work and the Spinneret - thank you. Have already started acquiring books on HTML and internet protocols after examining your tutorials and spinneret code.
My question: I am using a slightly modified version of HTTPServer. In my application, the server(Spinneret) sends a form to a browser and the browser user responds by filling out input fields and hitting a 'submit' button and the server gets the POST response. Is there a 'clean' way to have the server send a page back to the browser after receiving the POST response (so the user sees something other than the input form)?
I am thinking I could use the Request.setName method (and other SET methods from Request.spin as needed) to alter the POST response header (after processing the needed input form data) and call the staticFileHandler method, but this seems kind of kludgy.
Am I missing something obvious here?
If this question is too vague or not enough info, please let me know. Not trying to be abstruse, beginner HTML/Spinneret/HTTPServer here....
Thanks,
Nate
Comments
- Add an "action=page.htm" attribute to the form tag. In the dispatcher filter for "page" and the "POST" HTTP method. Process the POST. Let the StaticFileHandler render static page.htm.
- If the resulting page is dynamic, then you must create page dynamicly. Again filter for the requested page and the "POST" HTTP method in the Dispatcher method. Do NOT let the StaticFileHandler execute. Instead, build a dynamic page by taking advantage of the PushDynamicContent() method. Tx the dynamic page as the response.
Option 2:HTML page name is postme.htm. Notice the Action="postex.htm" Form attribute. This action is passed to the server. The server must filter for postex.htm not the page name postme.htm.
HttpServer snippet Filter for the file name "postex" and HTTP POST. invoke a custom handler - PostEx. PostEx builds a custom response. The if block returns without executing the StaticFileHandler.
While the two options above will work great. It is better to use the Spinneret as a service. Spinneret as a Service would be similar to option two except use AJAX (client JavaScript) to submit the request and parse the response. This method allows the programmer to offload processing to the client and the intent of HttpServer. This method would require design changes though.
The <form action= > was exactly what I was looking for. Thanks.
One issue I had: A form was POSTing four separate text input fields. If the inputted text and variables were over a certain length (POST header, 'Content-length' was over ~62) the last text variables were not being seen by the Response.Post method (it appeared to be returning a '0'.) On closer inspection of the Respone.Post method:
It appears to have a limit of 50 placed on the return position. I checked out the PASM code for the stringMethods, there seems to be a 2k upper limit on the searched string length (ie, appears as if there IS a bounding limit on the search). I removed the 't1 > 50' condition from the Response.Post method, and the problem seems to be solved. Can you tell me if I am creating a problem (is there something that uses the Response.Post method that should NOT look for more than 50 chars?), or is the upper limit of 50 a vestigial piece of code?
Thanks,
Nate
Stop using HttpServer and start using the new driver. The new driver has a much better request handler, has been thoroughly tested, is smaller, has more features, and is much more extensible.
http://code.google.com/p/propeller-w5200-driver/source/browse/trunk/#trunk%2F%20propeller-w5200-driver%2FSpinneret
I was using the code on from your 'servebeer' spinneret because it was convenient to your tutorial and I was unsure what was the most current.
After reading around in this forum more, I have downloaded the latest from Google. I'm sure I'm going to have more questions now that the newest has DHCP and other bells and whistles...
I realize the tutorial is based on the HttpServer. Mybe one of these days I'll find time to update the tutorial. If you have a handle on the HttpServer, the new stuff is much the same. The difference being a layered design. The cool thing is all the W5200 libraries can but used with the Spinneret and visa versa.
Check out Tom Cantrell's article. Tom did a great job explaining the firmware.
http://www.digikey.com/us/en/techzone/wireless/resources/articles/ethernet-orb-sees-all.html
I will post future questions under appropriate thread titles to help other people leaning about the Spinneret and your code and also so perhaps you will not have to keep answering the same questions over and over again... Great Digikey article.
Thanks for your help so far.
Nate