Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Grabbing session variables without being in a Web Application

 
Francesco Marchioni
author
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
forgive the strange question, let me explain better. Sometimes
in a client application I have to collect information (for log purposes)
about a web application. Let's say I have a String like "http://mysite/mypage.jsp?var1=5&var2=1"
Now I want to extract the URI information as well as variables from the client side. Let's say I'm not on the serverside staff so I cannot have my servlet pass this information in any way.
If I'm in a web context it's easy...just query the request object.
But what about if I'm not inside a Servlet ? can I build a HttpRequest object for the sole purpose of working on a URL, and extracting this info ?? or my only chance is to substring() the String ? (which, I admit, I hate it!)
Thanks a lot
Francesco
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't access the HTTP Session clientside as it is maintained purely on the server.
Only the session ID is sent to the client, either as part of the URL or as a cookie.
So you'll have to examine the HTTP headers and URL String and hope those contain the info you want.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're just asking about parsing that string to read all the variables. You can use StringTokenizer or regular expression Patterns several times:

Put that in a nice little parser class and don't lose it. This sounds like something you'll need to to again some day!
 
Francesco Marchioni
author
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks a lot for your answer.
Well I hoped it was possible somehow to "recycle" the parsing logic from
Servlet Api...never mind I'll build my own class and do it as suggested.
Regards
Francesco
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic