• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URL encoding and decoding

 
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are in the rt.jar under java.net package.

WP
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.
Sorry, if you are not going to do anything with jsp urls
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are there any alternatives? To working with XML 1.0?

thanks,
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
reply
    Bookmark Topic Watch Topic
  • New Topic