• Post Reply Bookmark Topic Watch Topic
  • New Topic

Splitting a string in 2 and turning it into hexadecimcal  RSS feed

 
Iain Emsley
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to port some Perl code into Java for a web app which requires cookies for authentication. The code that I'm trying to port is:


I'm trying to put the cookie into a string and then split it. Being more used to Perl (as I'm learning Java on the job), I've come into difficulties with splitting the cookie into variables e and p. I've tried to set up a
code block to take e and then use int.to Hex to turn it into hexadecimal. Ultimately the two strings, e and p, need to go into a hash to be checked for validity but I'll cross that bridge once I arrive at it.


I think that I've become lost following my own footsteps and would be grateful for some guidance further through the forest. I think I'm trying to do too much too quickly in regards to the processes and perhaps need to break them down further?

Ultimately I'm wanting to use this in a servlet as part of the authentication process in Tomcat.

Yours,

Iain
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch. I can only help a bit. You don't tell us which format the cookie text is in.
The line beginning for appears to be correct, but you need {} around the lines you wish to repeat. Otherwise you will only repeat the line in () with .equals("WALOGIN"). I think that line ought to have begun with if before the (.

By split, do you mean the split() method of the String class? If the text of the xookie is stored in the String you call xookie, you would invoke it with something like thisI think you will need to escape the hyphen which is a metacharacter in regular expressions, like this "\\-" in the regex String.

I am afraid I don't understand the bit about changing to hex; maybe somebody else can help. Or maybe if you explain it more fully . . .

Please try that lot and see whether that makes any difference. Try the splitting bit on its own, without the hex bit, see whether that works, then post again.

CR

There is a problem with posting here that it requires the word xookie be spelt wrongly. :roll:
 
Iain Emsley
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell,

Many thanks for the advice. I'll try this (once I've got rid of another bug) and let you know how I get on with it.

Iain
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!