This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URL encoding and decoding

 
Michele Smith
Ranch Hand
Posts: 421
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:

We need to URL encode and decode.

We need to provide a .jar file and use that .jar file to decrypt the item and use that for a parameter on the querystring.

Do you have any suggestions on how to create the .jar file?

Also do you know of any examples utilizing java servlets which are available for study?

Thanks,
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Encode and Decode are already built into most modern web-application frameworks.

If you're adding your own processing, then creating a jar with the class(es) is very easy in Eclipse.

If you package this jar with your war, or externally you should have no problems.

WP
 
Michele Smith
Ranch Hand
Posts: 421
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I know if it was built in to an existing application which I inherited?

Also I have found this technique here:

public class URLParamEncoder {

public static String encode(String input) {
StringBuilder resultStr = new StringBuilder();
for (char ch : input.toCharArray()) {
if (isUnsafe(ch)) {
resultStr.append('%');
resultStr.append(toHex(ch / 16));
resultStr.append(toHex(ch % 16));
} else {
resultStr.append(ch);
}
}
return resultStr.toString();
}

private static char toHex(int ch) {
return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10);
}

private static boolean isUnsafe(char ch) {
if (ch > 128 || ch < 0)
return true;
return " %$&+,/:;=?@<>#%".indexOf(ch) >= 0;
}

}


I need to call this class from a simple servlet.

I think I need to insert the call into this portion of the servlet:



Am I going in the right direction here?

Also do you know where I could find out about making the Decode URL class into a jar file?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64194
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why aren't you just using URLEncoder and URLDecoder?

And you use the word "decrypt". Encoding is not encrypting. I hope you aren't doing this for any security purposes!
 
Michele Smith
Ranch Hand
Posts: 421
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean importing it into the class?

If so can you name it? I tried a couple of things and my IDE / project cannot find it.

Thanks,
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are in the rt.jar under java.net package.

WP
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michele Smith wrote:
Am I going in the right direction here?


why cant you use JSTL ?

<c:url value=' servletPath ' >
<c:param name = 'key' value = 'data' />
</c:url>

if key/data contains any non alphanumeric then, param tag encode the data for you.
 
Michele Smith
Ranch Hand
Posts: 421
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks William, I got it, thanks a lot!

why cant you use JSTL ?

<c:url value=' servletPath ' >
<c:param name = 'key' value = 'data' />
</c:url>

if key/data contains any non alphanumeric then, param tag encode the data for you.


My questions are this, my parameter name is parentid

it's value is numeric.

I have never used JSTL before.

Where would I put that code?

One last thing, 'key' and 'data' refer to what exactly?

Thanks,
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michele Smith wrote:
I have never used JSTL before.

http://docs.oracle.com/javaee/5/tutorial/doc/bnakc.html
Michele Smith wrote:
One last thing, 'key' and 'data' refer to what exactly?

they are parameter name and it's value
 
Michele Smith
Ranch Hand
Posts: 421
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like JSTL is used in JSP can it be used in XML 1.0?

Thanks,
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
Sorry, if you are not going to do anything with jsp urls
 
Michele Smith
Ranch Hand
Posts: 421
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are there any alternatives? To working with XML 1.0?

thanks,
 
Michele Smith
Ranch Hand
Posts: 421
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I did as Bear suggested, using the


import java.net.URLEncoder;

and put this in my servlet:



When I reference my xsl stylesheet link with this parameter as follows:



I wonder what I might be doing wrong.

Thanks,
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic