• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing Query String Parameters Without A Query String in URL

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so I have 2 tables with 3 columns each with unique values, and the values in the columns are links that go to another page. These aren't forms that submit, they are href links that go to a different page, so I just need to preface with that.

The first tables columns each feature a unique identification number in the URL so it's something like localhost:8080/BLAH/servlet/page?idInQuestion=91

I need to cut out everything behind the question mark, and still get the page to load. So, how would I go about passing that parameter without using the query string?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Scott ScottMacD wrote:I need to cut out everything behind the question mark, and still get the page to load. So, how would I go about passing that parameter without using the query string?


Have a look at String.split().

Winston
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, right now my link is set up as (I'm using spring)

<spring: url var= "mylink" value="${servletPath}/myPath">
<spring:param name = theId value = "${id.theId}"/>
</ spring: url>

a href= onclick= onkeypress= title = ${id.theId}</a>

So, my question is since it's not set up directly as a string, how would I split it?, and also I need to prevent it from displaying the query string in the URL, but still pass what's in the query string, would it do that if I could?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't. Not with a link. And why? What issue is the query string causing?
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No issue, I was told to remove all parameters from every URL in the project I was working on, but everything I try bombs out.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds a lot to me like taking the tires off a car and then being surprised that it won't go anywhere. The query string is the way to carry request parameters on a link URL.

I think you need to find out what's actually trying to be accomplished so we can figure out what the actual goal is.
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's sort of a security thing. The organization I work doesn't want the parameters to be visibly displayed. I know it's been done before with a couple links that were in tabs, but the information in those was different than the information I have here, and I can't for the life of me replicate that process.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What sort of attacks is your organization worried about?

First of all, the application must be protected by TLS/SSL so that information is encrypted in transit.

Secondly, if the parameter values themselves are also sensitive data, they can be individually encrypted so that "over the shoulder" readers can't see any sensitive values on the URL.

Failing that, you'd need to turn every link into a form that POSTs itself so that the info is in the response body rather than in the query string. But that would not eliminate the need for TLS/SSL to protect the data in transit. And, a POST just might not be the correct HTTP method to use and I always hesitate to use this approach just for its supposed security benefits.

Neither of these approaches are trivial, so I'd make sure that the security concerns are actual and valid before devoting the resources to change all URLs.

What is the nature of this data that is considered insecure?
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in most of them it's different sorts of ID numbers, dates ,etc.

Here is what I've written currently, it's based on something that's worked for someone else, but it's not working for me, the page is now showing as a total blank.

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A lot of that code makes no sense and looks full of errors. So I'm not sure what you are trying to accomplish with it.

What page is blank? The page with this code on it? Or the page after clicking the link?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, you haven't attended to changing your display name yet. You must do that.
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a version of this code that somehow takes the URL with query string and sends the parameters through. I've tried rewriting it for the page I'm on, because if I use this one it creates tabs.
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also removed stuff from the onclick and onkeypress stuff.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rather than trying to copy code and then, frankly break it, you'd be better off deciding what you want the code to do and we can help you figure out how to do it.

So what is it you want to do with the links? You can't just drop the query string and expect the dropped data to still make its way to the request. What is it that you actually need to do?
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not trying to copy code, and break it. If the code I'm looking at has the functionality I need minus the fact that it has been set up to create tabs with internal links, instead of text based internal links, I am trying to take it and have it do the precise same thing.

I need the URL to appear in the address bar without the query string content, but still pass the parameters.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Scott ScottMacD wrote:I need the URL to appear in the address bar without the query string content, but still pass the parameters.


Impossible unless you convert all the links to form POSTs -- which I think is folly. But unless you have leverage to push back on whoever is making this decision, I suppose you have your marching orders.

Perhaps you could show the original code where you think this is happening.
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I missed that, but how do I do that? I am fairly new at this, and believe I tried something something similar last week.
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Scott ScottMacD wrote:OK, I missed that, but how do I do that? I am fairly new at this, and believe I tried something something similar last week.



OK, this is the original code for the link.

minus some stuff in the header above that sets up the servlet and context path. I believe I tried wrapping it as a form last week, but I possibly did it wrong.
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Scott ScottMacD wrote:I need the URL to appear in the address bar without the query string content, but still pass the parameters.


Impossible unless you convert all the links to form POSTs -- which I think is folly. But unless you have leverage to push back on whoever is making this decision, I suppose you have your marching orders.

Perhaps you could show the original code where you think this is happening.



Can you explain how to do that? I believe I've tried to, and I may have done it wrong, and gone back to the drawing board when it didn't.

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Except for the JavaScript, that looks like straightforward Spring code to create a link. I have no way of knowing what the JavaScript does (and, just for your future information, it's considered a poor practice to mix JavaScript into the markup like this).

Before embarking on replacing the link with a POST form, you need to check that that's the approach that the powers that be want you to take. Not only is it a lot of work if there are many links to be replaced, that approach has significant downsides (such as, no more bookmarking, no more refreshing). I do not recommend it.

I'd double check to see what the security issue really is. If it's the fact that query string contains sensitive data that shouldn't be revealed to even the users of the web app, then I'd investigate encrypting the param values before I replaced what should be a GET with a POST for artificial reasons.

If the issue is that the values are to be protected en route, then using TLS/SSL solves that problem with no code changes.
 
Scott C macDonald
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are 3 links that need to be replaced. What I need to know is how do I replace the links with post forms? Do I need to use javascript? Can you please give me some sort of example?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you need to do is to use a form with a hidden element instead of a link. Make sure that the method is "post" (it's usually the default, but be explicit for clarity). Within the form, in addition to the hidden input to hold the param data, create a submit button using the <button> element which you can use CSS to style to look like a link.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, you also need to use CSS to make the form an inline element; it's a block element by default.
 
Scott C macDonald
Greenhorn
Posts: 18
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I saw this message when I was in the grocery store yesterday, and had actually done this minus the CSS to turn the submit button into a hyperlink, so it confirmed I was doing the correct thing. You've been a great help. I just have one question. I just did the CSS it looks like a hyperlink now, but now it simply won't allow the submission. If I delete the tags that turn the button into looking like a hyperlink the button will submit and take me the next page, if I had them I can click, and it won't do anything. Any idea why?

EDIT: I got it.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad that you've got it!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic