aspose file tools*
The moose likes JSP and the fly likes alternative to query string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "alternative to query string" Watch "alternative to query string" New topic
Author

alternative to query string

Mohammad Atiq Kazi
Greenhorn

Joined: Apr 01, 2008
Posts: 9
Hello All,

Please let me know if there is any alternative to query string for passing data. The problem is that its a link (href) through which query string is passed and hence we cannot use request or session objects. Please suggest on this..

Regards
Atiq


Mohammad Atiq<br />SCJP 5.0
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

You could use a form with method=post, and your link could be a javascript call that submits the form.


[ August 27, 2008: Message edited by: Steve Luke ]

Steve
Mohammad Atiq Kazi
Greenhorn

Joined: Apr 01, 2008
Posts: 9
Thanks for the reply..

But my problem is that the link will be visible in mobile handset and when the user clicks on it, it will connect to application and based on the query string it will retrieve information and send it back to the user. I need to find a way to remove the query string and shorten the url.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30776
    
157

Mohammad,
If you use a POST, just the action name is shown in the URL. The parameters are not shown.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18675
    
    8

Is your problem that the URL is too long, or is it that there is a visible query string?
Mohammad Atiq Kazi
Greenhorn

Joined: Apr 01, 2008
Posts: 9
Thanks for the replies...

My requirement is to shorten the url. Its a link which will be visible in mobile handset with some query string in it (to say in midlet application). The midlet will communicate to application to fetch data. I am searching for an alternative to query string for shortening url.

Regards
Atik
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
I has been a while since I looked at midlet capabilities.

Are you saying the a midlet can ONLY generate a GET? I thought POST was also possible.

Bill
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Another alternative would be to use 'friendly' urls, like:
http://myserver.com/context/Steven/1/displayage.jsp
rather than
http://myserver.com/context/diaplayage.jsp?name=Steven&age=1

It makes the URLs easier to read and gets rid of the query string, but makes it a bit more complicated to put them in/pull them out of the URL. They must be ordered (if you couldn't do /context/1/Steven/displayage.jsp if the page expected /context/Steven/1/displayage.jsp) and you would need to implement a control structure that can correctly parse the URL, pull out the parameters then forward to the proper display. Not a big issue if you are using a FrontController.

For small number of parameter name/value pairs the difference is minimal (as you can see above, but for large number of name/value pairs the difference is large.

(I have also seen 'friendly' urls written as: http://myserver.com/context/displaypage.jsp/<param value 1>/<param value 2> instead of http://myserver.com/context/<param value 1>/<param value 2>/displaypage.jsp I guess because it makes it easier to parse out the directory structure of where the displaypage.jsp page is... not sure which is preferred or normal, but I like the having the displaypage.jsp at the end...)
Mohammad Atiq Kazi
Greenhorn

Joined: Apr 01, 2008
Posts: 9
Thanks for your replies..

The url will be generated in a dynamic way. We cannot create a separate directory for each url here. Only a single jsp page handles request and based on the query string passed, it will fetch data from the database and send it to midlet. The url looks like this
http://abc.com/abc.jsp?soId=56&pd=26
I need to shorten this url and make it smaller and meaningful. Here abc.jsp handles all requests.

Regards
Atik
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Using friendly URL's doesn't mean you have to use directories. But if you are using a JSP as a front controller it does make things a bit more difficult. If you were using a Servlet, for example, you could map it to something like:

/abc/*

And then you could have a URL like:

/abc/56/26

If the 'soId' always comes first and the 'pd' always comes second that is really easy to parse. Then you just do whatever with those values as you normally would as if they came in on a regular query string. I'd bet you can map a JSP similar to mapping a servlet but its been a while since I've done that so I'd have to go digging myself. But that does shorten your URL and makes it meaningful:

http://abc.com/abc/56/26/


GenRocket - Experts at Building Test Data
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Making query data part of the URL as in the GET example where "abc" addresses a servlet and the numbers are submitted data:
/abc/56/26


is the REST approach to using standard HTTP for web services.
Sun is supporting the open-source Jersey project for the server side of RESTful web services. Here is my simple article on an example.

Jersey uses Java annotations to take care of parsing that URL for you.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: alternative to query string