Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Pre-packaged solution to parse HTTP ASCII results?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have an applet that is currently executing a PERL script on the applet's host machine. The PERL script runs a SQL query against our MySQL database and returns the results over HTTP.
The results are URL Encoded, something like:
param1=value1,¶m2=value2...
I am currently investigating how to parse the returning results. I would rather use an existing class to do this.
There is a class "HTTPRequest" (getParameter method), but it seems to be only available if you are creating a servlet.
My questions are:
1. How do I use this class if I am not creating a servlet?
2. Does anyone know of any other HTTP-parser-type class that I could use?
3. Is there a better way to do this? It bothers me that I will not be able to understand the order of the results or which parameter is being passed without some extensive logic.
Thanks in advance.
Tracy Williams
 
Saloon Keeper
Posts: 22289
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if I quite understand you, but I think one or the other will apply:
If the server is returning a URL to your applet, you can parse it using the java.net.URL class for the major components, at least. As for breaking down the operands, you might just want to see if you have source for the javax.servlet.HTTPRequest class (I'm not sure that's quite the right name and package, but something like that). If you do, you could either plunder its code or find out what utility package it's using.
URL parameter encoding isn't real complex - just a bunch of operands separated by "&" with spaces replaced by "+" and more complex characters gicen by "%" followed by a hex code. So you could split the operands with the java text parser class, use the String character subsitution class to change the "+" to space and the only really hard stuff would be the hex codes. But it's reinventing the wheel, so you should try my first suggestion and/or google for a "Java URL decoder".
More common for servlets is that they make up a URL request to a server via class HttpURLRequest and et the answer back as a stream. If you're NOT using the URLRequest class, you really should be, since it also handles the HTTP headers (including cookies for session info) automagically. Using raw socket I/O is more trouble and more stuff you have to debug. The returned stream is just that - a data stream, and is commonly lines of text or XML, though anything allowable as long as it can make it over HTTP.
 
Tracy Williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply! I'll let you know what happens.
Tracy
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic