aspose file tools*
The moose likes JSP and the fly likes Targeting only GET variables using paramValues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Targeting only GET variables using paramValues" Watch "Targeting only GET variables using paramValues" New topic
Author

Targeting only GET variables using paramValues

Jeremy Wischusen
Greenhorn

Joined: Nov 03, 2008
Posts: 6
This is mostly a curiosity question as the actual implementation I will be using this for will only have the GET variables, but I have been searching for an answer to this for two days now and have not com up with anything.

My background is in PHP and if I am on a page that has both POST and GET variables I can target those variables separately using either $_GET or $_POST.

Currently I am looping through the paramValues object and it is spitting out both POST and GET variables. Is there a way only to target the GET variables. For some context, here is the code I am playing with:

HTML Form Page:

Form Processing Page:


Outputs:


[ November 03, 2008: Message edited by: Jeremy Wischusen ]

Jeremy Wischusen<br />Flash - Flex - AIR - PHP Developer <a href="http://www.visualflowdesigns.com/" target="_blank" rel="nofollow">http://www.visualflowdesigns.com/</a> Blog | <a href="http://www.linkedin.com/in/jeremywischusen" target="_blank" rel="nofollow">http://www.linkedin.com/in/jeremywischusen</a>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Firstly, there's no such thing as POST and GET parameters. Your HTTP method is either a GET or a POST, but can't be both.

I believe that the (badly named) PHP distinction is between parameters passed in the query string, and those passed in the request body.

In Java, no distinction is made between the two. In fact, using both is considered a poor practice. In a GET request, the request parameters should (must) be on the query string, in a POST in the request body.
[ November 03, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jeremy Wischusen
Greenhorn

Joined: Nov 03, 2008
Posts: 6
I understand that the method header is either POST or GET. However, there is absolutely nothing stopping you from providing both POST data and URL variables and the example I posted shows that even Java will take the data from both places on the same page.

While Java may consider it poor practice to use both POST and GET variables, both PHP and ColdFusion make distinctions between them using POST and GET objects and ASP has Request.Form("Name") making it possible to distinguish between the origins of the variable. Java is the first server side language that has not made a distinction and not provided a methods for distinguishing between the sources.


Originally posted by Bear Bibeault:
Firstly, there's no such thing as POST and GET parameters. Your HTTP method is either a GET or a POST, but can't be both.

I believe that the (badly named) PHP distinction is between parameters passed in the query string, and those passed in the request body.

In Java, no distinction is made between the two. In fact, using both is considered a poor practice. In a GET request, the request parameters should (must) be on the query string, in a POST in the request body.

[ November 03, 2008: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Originally posted by Jeremy Wischusen:
I understand that the method header is either POST or GET. However, there is absolutely nothing stopping you from providing both POST data and URL variables ...
I didn't say that there was. I said that calling them "GET variables" wasn't accurate. Also that it wasn't considered a good practice, not that it couldn't be done.

If this is something you really really need to do, you could parse the request yourself rather than letting the container code do it for you.
Jeremy Wischusen
Greenhorn

Joined: Nov 03, 2008
Posts: 6
Yeah I think we might just be debating semantics. You basically answered my question. Thanks.

Originally posted by Bear Bibeault:
I didn't say that there was. I said that calling them "GET variables" wasn't accurate. Also that it wasn't considered a good practice, not that it couldn't be done.

If this is something you really really need to do, you could parse the request yourself rather than letting the container code do it for you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

My pleasure.

Curious: why do you need the distinction?
Jeremy Wischusen
Greenhorn

Joined: Nov 03, 2008
Posts: 6
Well partially just out of curiosity. This is just the first language I have used that did not make some distinction between the source of the variables, so I wanted to make sure that I was not missing something (wouldn't be the first time).

The code I posted is a test attempt at automating this tracking process I have been doing for work. In the current implementation it will not actually be an issue as actually the entire reason for the URL variables is to pass along data from the form that is no longer available as post data.

There is an intermediary global processing page (used for multiple sites) which then forwards you on to a final landing page. So I can't edit the processing page (as that would mess up other sites) and by the time I get to the landing page, the post data is gone (since it is a redirect). So the current solution is to grab the values from the form that we need and pass them on as URL variables in the redirect.

In all honesty it is probably more of an thought exercise as I could never guarantee that all of the URL variables were relevant to the tracking code. So probably what I will end up doing is using a Map that specifies the request data that the tracking system is interested in (each site is interested in slightly different data)

So all of that is a really long winded way of me saying that basically it is something I am used to being able to do and I was just a bit surprised that I was not finding any way of doing it with JSP.

Again thanks for the help. Hope I was not coming off as too much of a pain in the ***.

Originally posted by Bear Bibeault:
My pleasure.

Curious: why do you need the distinction?
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
The servlet has a doPost and doGet method in which you could determine if a post or a get was issued. However, java does abstract the two and hide these details in teh Request ohject. here is some more info on the matter: http://www.esus.com/javaindex/j2ee/servlets/servletdogetdopost.html
http://www.codestyle.org/java/servlets/faq-API.shtml#dopostcall
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServlet.html


http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Originally posted by steve souza:
The servlet has a doPost and doGet method in which you could determine if a post or a get was issued.
Determining the HTTP method was not the issue. The issue was differentiating between request parameters placed on the URL (in the query string), versus request parameters embedded in a POST body.
Jeremy Wischusen
Greenhorn

Joined: Nov 03, 2008
Posts: 6
Thanks. Appreciate the resources.

Originally posted by steve souza:
The servlet has a doPost and doGet method in which you could determine if a post or a get was issued. However, java does abstract the two and hide these details in teh Request ohject. here is some more info on the matter: http://www.esus.com/javaindex/j2ee/servlets/servletdogetdopost.html
http://www.codestyle.org/java/servlets/faq-API.shtml#dopostcall
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServlet.html
 
 
subject: Targeting only GET variables using paramValues