wood burning stoves*
The moose likes HTML, CSS and JavaScript and the fly likes POST data w/o form? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "POST data w/o form?" Watch "POST data w/o form?" New topic
Author

POST data w/o form?

Vincent Micchia
Greenhorn

Joined: Nov 09, 2011
Posts: 10

Basically I'm wondering if there is a way to send POST data without actually using a form. I ask this because what I want to do is take data from a text area ans seperate it then send the values to a page that currently takes data from seperate form fields.

I only want to do this because I already have the page that gets the results for the request it just currently take data differently. I'm new to this so if I could just use the existing page and feed data into it rather than make a new one it would be great.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60817
    
  65

I'm not exactly sure what you are trying to accomplish by your description, but be aware that hacking around is likely to create more confusion that just doing things in a straight-forward manner.

That said, the only other way to generate a POST from a browser other than a form is via Ajax.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vincent Micchia
Greenhorn

Joined: Nov 09, 2011
Posts: 10

Bear Bibeault wrote:I'm not exactly sure what you are trying to accomplish by your description, but be aware that hacking around is likely to create more confusion that just doing things in a straight-forward manner.

That said, the only other way to generate a POST from a browser other than a form is via Ajax.


I understand. What it basically is is that I have a existing ability on my site to do this, but want a user to be able to submit the information in a different way.

Currenty a user can enter a item and a quantity(only 10 of these at the moment each with their own text box), then these get sent to a page that displays the result. What I want to do is let the user enter the information in a text area via comma seperated values (so they can use as many as they want at once) but still come to the same results page. So for that to work I need to parse the data from the text area and then send it with the same POST values as the individual text boxes would have had.

New to this so that seems like the simplest way but perhaps not so much.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It's the simplest way only if you think the users are going to type correctly-formatted data 100% of the time. Which, of course, they aren't. So now you have to write some code to parse the CSV data and deal with the cases where they didn't put in enough fields into a row. Maybe they hit the period instead of the comma, or maybe they accidentally put in two commas together, or put everything into a single line because they didn't understand (or read) the instructions. And so on. Not the simplest way at all.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60817
    
  65

I think that you may be digging yourself a very deep, very dark, and very dangerous hole.

What is the motivation for this in the first place? Do you have a requirement to allow CSV data entry? I can't imagine any user wanting to enter data in that way -- seems rather silly. But what's the reason for the whole task?
Vincent Micchia
Greenhorn

Joined: Nov 09, 2011
Posts: 10

Well it's a precursor to allowing excel data to be imported. But this is faster and works for the time being. Users have been asking for something like this so yeah here I am.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60817
    
  65

Seems to me that a better solution would be to refactor the original servlet to use a lower-level API that both forms of input could share. How are you planning on validating the CSV?
Vincent Micchia
Greenhorn

Joined: Nov 09, 2011
Posts: 10

Bear Bibeault wrote:Seems to me that a better solution would be to refactor the original servlet to use a lower-level API that both forms of input could share. How are you planning on validating the CSV?


Well I can't validate the first value in each line other than it being there. The second value had to be a number snd I was hoping I could make sure there were no more than 2 values before the \n if that is possible.

Edit: was going to split the values into and array first and then check every other value for the needed validation.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Vincent Micchia wrote:Well it's a precursor to allowing excel data to be imported. But this is faster and works for the time being. Users have been asking for something like this so yeah here I am.


You might consider skipping over the quick-and-dirty method, then, and going straight to working with Excel uploads. I'm doing that right now, as it happens; extracting data from Excel and validating it in a servlet isn't too bad, but you have to have something of a framework in place if you're going to be dealing with multiple formats. One thing you could try (which I haven't done yet) is to provide empty Excel spreadsheets with macros which control what can be entered where. You still have to do the same validation on the server, but your users will thank you if they can be sure they can just upload their spreadsheet and be sure it contains valid data.
Miku Ranjan
Ranch Hand

Joined: Oct 11, 2011
Posts: 98
Hi,
If your aim is to send some post data without form submiting you can use ajax for that or you can submit your form to iframe so your total page will not be refresh.
Vincent Micchia
Greenhorn

Joined: Nov 09, 2011
Posts: 10

Well I wrote it in php because I'm considerably more familiar with that but it would seem that I'm not going to be able to do it that way. Any help turning this into jsp would be much appreciated.



Edit: removed code for displaying the array don't need that was just for testing.
Vincent Micchia
Greenhorn

Joined: Nov 09, 2011
Posts: 10

Aslo as a side note. The code that this form data gets submitted to does all the validation and error checking already. For me it's really just getting the data in the correct format (form field post data.)
 
Don't get me started about those stupid light bulbs.
 
subject: POST data w/o form?
 
Similar Threads
Using Java with a web application without an API
Quick PHP Design Question
Query about Request Forwarding
url data into variable
Avoiding JSTL-SQL for a Comment System