Urldecode or urlencode
I don't know if I have typed them right!
urldecode or urlencode, how and when should they be used in JSP?
I don't know if I have typed them right!Maybe! Maybe not!
urldecode or urlencode, how and when should they be
used in JSP?What are these?!? Methods? Of which class? Where are the API docs located?
Similar Messages
-
URLDecoder / URLEncoder don't like non-ASCII, even with UTF-8 explicit
Here's my code:
import java.net.*;
import java.io.*;
public class Decoder
public static void main(String[] args)
if (args.length != 1) {
System.err.println("Usage: Decoder UTF-8-URL-encoded-string");
System.exit(1);
String sampleString = "auflerhalb";
try {
for (int k = 0; k < args[0].length(); k++) {
System.out.println("Char is " + Character.codePointAt(args[0], k));
System.out.println();
String queryText = URLDecoder.decode(args[0], "UTF-8");
for (int k = 0; k < queryText.length(); k++) {
System.out.println("Char is " + Character.codePointAt(queryText, k));
String newText = URLEncoder.encode(queryText, "UTF-8");
System.out.println(newText);
System.out.println();
for (int k = 0; k < sampleString.length(); k++) {
System.out.println("Char is " + Character.codePointAt(sampleString, k));
System.out.println(URLEncoder.encode(sampleString, "UTF-8"));
catch ( UnsupportedEncodingException e ) {
System.err.println("Couldn't decode querytext as UTF-8");
System.exit(0);
}The problem I'm encountering is that characters such as the German S-like character aren't being decoded correctly, or encoded correctly. When I run this file, on Linux, MacOS X or Solaris 10, I get this:
% java -version
java version "1.5.0_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_07-b03, mixed mode)
% java -cp . Decoder "au%DFerhalb"
Char is 97
Char is 117
Char is 37
Char is 68
Char is 70
Char is 101
Char is 114
Char is 104
Char is 97
Char is 108
Char is 98
Char is 97
Char is 117
Char is 65533
Char is 101
Char is 114
Char is 104
Char is 97
Char is 108
Char is 98
au%EF%BF%BDerhalb
Char is 97
Char is 117
Char is 223
Char is 101
Char is 114
Char is 104
Char is 97
Char is 108
Char is 98
au%C3%9Ferhalb
The decimal code point of the German S is 223; the hex code point is DF. Yet the decoder completely mangles the string containing %DF, and the internal string, which clearly has the right decimal code point, is mangled by the encoder; C3 9F has absolutely nothing to do with 223.
I can't figure out for the life of me what I'm doing wrong. I've taken a look at the source code for URLDecoder.java, and it really appears that it's broken; it decodes hex sequences into a byte array, but Java bytes are signed, between -128 and 128. Could this be what's going on? Hex code points up to 127 work fine; above it don't work at all. Try my function with %7E instead of %DF, and then with %81.
Can this really be broken?
Thanks in advance -
Sam Bayer
The MITRE Corporation
[email protected]The decimal code point of the German S is 223; the hex code point is DF.
Yet the decoder completely mangles the string containing %DF, and the
internal string, which clearly has the right decimal code point, is mangled
by the encoder; C3 9F has absolutely nothing to do with 223.I don't think you understand what's going on. I haven't checked the Unicode table but let's assume that hex-DF is the Unicode code point for that character. That means it's in the range which UTF-8 will encode in two bytes. I haven't run it through the algorithm but it's quite likely that the result would be C3 9F, since that's what happened when you did it. It would certainly be two bytes and not one, contrary to what you expect. -
URLEncoder and URLDecoder for posting XML Strings
Hi All
I need to post an XML string to another website using POST.
I have some java code that generates the XML string and sets the request object with this parameter. In my JSP I need to assign this to a hidden form element so that when a user clicks on "Submit", the destination site can extract the xml string.
The problem i am facing is that while setting the hidden form element
e.g. <input type=hidden name=xmlstr value= //Set it by reading the parameter from the request object.
only the initial part of the string is picked up i.e. only upto the first double quotes " i.e. upto <?xml version=
I am thinking of using URLEncoding to encode the xml while posting and URLDecoding to decode this xml.
Is there a better way of doing this ?
Thanks
BitsI think that is the 'correct' thing to do. parameter values must be URLEncoded whether being posted or not.
-
Problems with urldecoding of %
hi,
in my servlet's post method i set
request_.setCharacterEncoding("UTF-8");
and then i gonna urldecode the parameters with
String value = request_.getParameter(PARAM);
String decValue = URLDecoder.decode(value.trim(), "UTF-8");
everything seems to work fine (even for some chinese utf-8 codes).
the only problem i got now is the "%".
i know that the urlencoded value is %25. however when i read out the
parameter there is only the % left (before i urldecode it). i don't quite
understand why this happens. i thought i should get the %25 before i
decode it. i am a bit puzzled because it works with other unicodes.
anybody out there who knows what happens?
thanx.You don't need to decode it, the server already does it for you. Just call setCharacterEncoding and getParameter and you're done.
-
greetings,
I have a form on my web site that will remember you information from the last time you filled it out.
Upon submitting the form, I store the values in a cookie using javascript. When you load the form the next time, I use JSP to read in the cookie, parse out the appropriate values and set them to the value attributes of the various form elements.
This all works fine in IE but for some reason netscape is returning these values URLencoded, I think.
For email address, I am getting:
davep%40example.com
instead of
[email protected]
I tried to apply the urlDecode method to the string as such:
emailVal = urlDecode(emailVal);
but got the following error:
/var/tomcat4/work/Standalone/localhost/raindance/content/trybuy/signup_services_jsp.java:145: cannot resolve symbol
symbol : method urlDecode (java.lang.String)
location: class org.apache.jsp.signup_services_jsp
emailVal = urlDecode(emailVal);
What am I doing wrong?check java.net.URLDecoder for syntax.
-
Hi!
I'd like to know if you can help me about this topic
I have a class which sends a xml message throug http, method POST with destination a servlet.
The content type is: application/x-www-form-urlencoded
The charset type is: ISO-8859-1
When this xml arrives to the servlet, my log shows this one:
2006-12-05 12:41:10,017 [http-8080-Processor2] ERROR GENERAL - error(URLDecoder): java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "gE"
What's wrong about it?...
Any help would be appreciated.. Thank you.
Best regards,
Abelardo.WOW MAN !!
It worked !!! U saved me a lot of time and efort !!
I never knew that I was a FOOOL coz I cudn't think on those lines !!
I also didn't know that there r xtremely intelligent people like u who can reply to a question in just 1 short and simple line....
Thanx man...thanx alot !! -
G'day all, I'm receiving a column from a database that is an encoded URL request string. We've been using a SQL Server function to decode this URL but recently the string coming in has 4000+ parameters which is taking a while to parse through the function
so I'm looking to see how a SSIS script component can handle the equivalent. However, when I try to include the System.Web namespace (using C#), it doesn't give me the option to choose subpackages (either Server or HttpUtility, not sure which will be the appropriate
package), any idea how I get this package available? Do I have to have a HTTP connection manager to make these available or have I missed something?
TIAHi TIA,
According to your description, you are trying to use Server or HttpUtility class to decode an encoded URL request string. While after adding System.Web namespace, you still couldn’t use Server or HttpUtility class.
From the
document, we can know that the HttpUtility class is included in System.Web.dll assembly System.Web namespace. Based on my research, it seems that the System.Web.dll assembly is not referenced by default in new projects.
So to fix this issue, please right-click References in the Solution Explorer and choose Add Reference, then select System.Web in .NET pane. Then we can use HttpUtility.UrlDecode or HttpServerUtility.UrlDecode method to decode the URL string.
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
URLENCODE how to use it?
Hi there...
I am in desperate need to use the URLEncode functionality in the jsp under weblogic
before sending a digital buffer inthe query string on the URL.
plztell me how to do it...
Plz.tell me asap.
Thanx in advance,
Regards,
Mandar.
Here's a short example:
import java.net.URLEncoder;
String unencoded = "How are you?";
// Encode the String
String encoded = URLEncoder.encode(unencoded);
// Append encoded to the query String...
Hope that helps,
Nils
Mandar wrote:
>
> Hi there...
> I am in desperate need to use the URLEncode functionality in the jsp under weblogic
> before sending a digital buffer inthe query string on the URL.
> plztell me how to do it...
> Plz.tell me asap.
> Thanx in advance,
> Regards,
> Mandar.
============================
[email protected]
-
Problem with URLDecoder.decode(s, enc)
Hi!
I'm having problems with the URLDecoder.decode(s, enc) method... When I send a string, encoded with the Javascript escape() function, to the server side of my application, I get a problem decoding it using this:
myString = URLDecoder.decode(myString, "iso-8859-1");It gives me this error: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "u2"
My html defines the encoding as follows:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />The string being submitted contains a special apostrophe ( ' ) copy/pasted from MS Word wich then translates it as %u2019 (what's that??? Unicode???).
Can anyone tell me what is happening? How can I encode / decode this properly?I'm having exactly the same issue.
Did you solved the problem?
Regards,
Gabriel -
Wron number of arguments error on URLEncoder.encode(language,
the following is the code which is an example in The complete Reference JSP
I ran this in tomcat
it shows an error which is showed down this code.The place where error occuring is underlined in the code
<%@ page session="false"
import="java.io.*,
java.net.*,
java.util.*" %>
<html>
<head>
<title>Using Cookies to Store Preferences</title>
<style><%= STYLESHEET %></style>
</head>
<body>
<table border="0" cellspacing="3" width="500">
<%-- Company logo --%>
<tr><td>
<img src="images/lyric_note.png">
</td></tr>
<%-- Language preference bar --%>
<tr><td class="LB">
<%= getLanguageBar(request) %>
</td></tr>
</table>
<%-- Localized greeting --%>
<h1><%= getGreeting(request) %></h1>
<%-- Store language preference in a persistent cookie --%>
<% storeLanguagePreferenceCookie(request, response); %>
</body>
</html>
<%!
// ===========================================
// Helper methods included here for
// clarity. A better choice would be
// to put them in beans or a servlet.
// ===========================================
* The CSS stylesheet
private static final String STYLESHEET =
"h1 { font-size: 130%; }\n"
+ ".LB {\n"
+ " background-color: #005A9C;\n"
+ " color: #FFFFFF;\n"
+ " font-size: 90%;\n"
+ " font-weight: bold;\n"
+ " padding: 0.5em;\n"
+ " text-align: right;\n"
+ " word-spacing: 1em;\n"
+ "}\n"
+ ".LB a:link, .LB a:active, .LB a:visited {\n"
+ " text-decoration: none;\n"
+ " color: #FFFFFF;\n"
+ "}\n";
* Creates the language preference bar
private String getLanguageBar
(HttpServletRequest request)
throws IOException
String thisURL = request.getRequestURL().toString();
StringBuffer sb = new StringBuffer();
appendLink(sb, thisURL, Locale.ENGLISH);
appendLink(sb, thisURL, Locale.GERMAN);
appendLink(sb, thisURL, Locale.FRENCH);
appendLink(sb, thisURL, Locale.ITALIAN);
String languageBar = sb.toString();
return languageBar;
* Helper method to create hyperlinks
private void appendLink
(StringBuffer sb, String thisURL, Locale locale)
throws UnsupportedEncodingException
if (sb.length() > 0)
sb.append(" ");
String language = locale.getLanguage();
sb.append("<a href=\"");
sb.append(thisURL);
sb.append("?language=");
sb.append(URLEncoder.encode(language, "UTF-8")); sb.append("\">");
sb.append(locale.getDisplayName(locale));
sb.append("</a>\n");
* Gets the greeting message appropriate for
* this locale
private String getGreeting
(HttpServletRequest request)
Locale locale = getLocaleFromCookie(request);
ResourceBundle RB = ResourceBundle.getBundle
("com.jspcr.sessions.welcome", locale);
String greeting = RB.getString("greeting");
return greeting;
* Determines the locale to use, in the following
* order of preference:
* 1. Language parameter passed with request
* 2. Language cookie previously stored
* 3. Default locale for client
* 4. Default locale for server
private Locale getLocaleFromCookie
(HttpServletRequest request)
Locale locale = null;
String language = request.getParameter("language");
if (language != null)
locale = new Locale(language);
else {
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies;
String name = cookie.getName();
if (name.equals("language")) {
language = cookie.getValue();
locale = new Locale(language);
break;
if (locale == null)
locale = request.getLocale();
return locale;
* Stores the language preference
* in a persistent cookie
private void storeLanguagePreferenceCookie
(HttpServletRequest request, HttpServletResponse response)
Locale locale = getLocaleFromCookie(request);
String name = "language";
String value = locale.getLanguage();
Cookie cookie = new Cookie(name, value);
final int ONE_YEAR = 60 * 60 * 24 * 365;
cookie.setMaxAge(ONE_YEAR);
response.addCookie(cookie);
%>
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occured between lines: 45 and 173 in the jsp file: /chap08/examples/cookies/CookieBasedWelcome.jsp
Generated servlet error:
C:\tomcat\jakarta-tomcat-4.0\work\localhost\_\chap08\examples\cookies\CookieBasedWelcome$jsp.java:75: Wrong number of arguments in method.
sb.append(URLEncoder.encode(language, "UTF-8"));
^
An error occured between lines: 45 and 173 in the jsp file: /chap08/examples/cookies/CookieBasedWelcome.jsp
Generated servlet error:
C:\tomcat\jakarta-tomcat-4.0\work\localhost\_\chap08\examples\cookies\CookieBasedWelcome$jsp.java:110: Wrong number of arguments in constructor.
locale = new Locale(language);
^
An error occured between lines: 45 and 173 in the jsp file: /chap08/examples/cookies/CookieBasedWelcome.jsp
Generated servlet error:
C:\tomcat\jakarta-tomcat-4.0\work\localhost\_\chap08\examples\cookies\CookieBasedWelcome$jsp.java:119: Wrong number of arguments in constructor.
locale = new Locale(language);
^
3 errors
But i have even checked the syntax of encode at which is exactly matching
http://java.sun.com/j2se/1.4.2/docs/api/java/net/URLEncoder.html
Kindly let me know what is the reason.......Check the Java API for this:
There is a specific note for the method, which reads as follows:
Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilites.
It's always better to look in API docs.
Annie. -
SOAP Adapter with application/x-www-form-urlencoded
You can use the content type "application/x-www-form-urlencoded" in a SOAP adapter?
Thank you.I did the configuration below:
"Here you have to use below configuration parameters for Module
Transform.Class = com.sap.aii.messaging.adapter.Conversion
Transform.ContentType = application / x-www-form-urlencoded "
However, got the following error:
=======================================================================================================
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <!-- Inbound Message
-->
- <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="1">
<SAP:Category>XIAdapterFramework</SAP:Category>
<SAP:Code area="MESSAGE">GENERAL</SAP:Code>
<SAP:P1 />
<SAP:P2 />
<SAP:P3 />
<SAP:P4 />
<SAP:AdditionalText>com.sap.engine.interfaces.messaging.api.exception.MessagingException: java.lang.ClassNotFoundException: com.sap.aii.messaging.adapter.Conversion -
Loader Info -
ClassLoader name: [sap.com/com.sap.aii.af.mod.trans.app] Living status: alive Direct parent loaders: [system:Frame] [service:servlet_jsp] [service:ejb] [library:engine.j2ee14.facade] [library:com.sap.base.technology.facade] [library:com.sap.aii.af.lib] [library:com.sap.aii.af.sdk.lib] [service:com.sap.aii.af.cpa.svc] [service:com.sap.aii.af.svc] [service:com.sap.aii.adapter.xi.svc] [library:com.sap.aii.adapter.lib] Resources: C:\usr\sap\PI1\DVEBMGS04\j2ee\cluster\apps\sap.com\com.sap.aii.af.mod.trans.app\EJBContainer\applicationjars\com.sap.aii.af.mod.trans.ejb.jar -
</SAP:AdditionalText>
<SAP:Stack />
<SAP:Retry>M</SAP:Retry>
</SAP:Error>
=======================================================================================================
Any suggestion?
Thank you.
Regards,
Bruno -
Could someone PLEASE help me on the syntax for URLdecoding?
In the code below, I want to URLdecode the "description" that
I am displaying in the textfield.Can you give us a little more information about the
"description" data that you're trying to display. You could try the
top level function un_escape() (remove the underscore – the
word is censored on this forum).
myHolder.myTextField.text = un_escape(e.target.description);
//again, remove the underscore
TS -
ASCII equivalent of CF's URLDecode?
Hello, everyone.
Even though I've been working with CF for over a decade, this is going to sound like a total n00b question. I'm just drawing a blank, right now. Google isn't much help.
Is there an ASCII equivalent of URLDecode??
Where I work, everything that is inserted into a database goes through a filter that changes certain characters to their ASCII equivalent (ie, the less than "<" is altered to "<"). For displaying the data, I need to revert the < back to < for formatting (there are <br /> in place of line breaks, in the data.)
If not, I suppose I should check cflib to see if there is a UDF. Hmm..
Respectfully,
^_^Well, first, that's not ASCII encoding, that's HTML Entity Encoding.
Second, no. There is not a built-in function for decoding HTML entities. The purpose of the function is to use it when displaying output to the screen, not to use it before sotring data for later use.
Obviously that doesn't help since you already have a system that encodes before putting data into the DB. So you need a way to decode it.
If you are using CF8 or CF9, with all of the security hotfixes installed, or you are using CF10, then you'll have ESAPI available to you via Java integration. ESAPI is a security tool from OWASP with built-in encoders and decoders. You can use those. Here is how.
<cfoutput>
<cfset string = "<hi>" />
<cfset list = createObject("java", "java.util.ArrayList") />
<cfset htmlCodec = createObject("java", "org.owasp.esapi.codecs.HTMLEntityCodec") />
<cfset list.add(htmlCodec) />
<cfset encoder = createObject("java", "org.owasp.esapi.reference.DefaultEncoder").init(list) />
#string#
<br />
#encoder.decodeForHTML(string)#
</cfoutput>
Hope that helps. -
URLEncodedFormat and URLdecode
I am passing some dynamic variables through the URL as
name/value pairs and before doing so I'll put the value variable
through the URLEncodedFormat function to take care of special
characters. However, when I get to the other page I noticed that
when I use that variable (I'm guessing it is now in the URL scope)
in a form field, or even just output it to the page, it displays
properly. That is it seems to automatically decode the value of the
name/value pair without using the URLdecode function. So is
URLdecode necessary?It's automatically decode the value, but to be safe use
URLDecode().
p.sim -
URLEncodedFormat() / URLDecode
I found the live docs version of these 2 functions, but does
anyone know a
place to find a easier explanation on how to use these?
I know to use the URLEncodedFormat() you would use:
<cflocation
url="page.cfm?var=#URLEncodedFormat('Form.variabletosend#')">
But I am not sure how to 'decode' it on another page to use
it as a variable
on another page.
Thanks
Wally Kolcz
Developer / Support1. You need to use URLEncodedFormat() for every value you
pass, not for the entire query string.
2. You cannot arbitrary apply URLDecode() in your
application, if you receive values, as Cold Fusion variables.
Consider the following example:
<cfset mvar="C/C++">
<a
href="test.cfm?mvar=<cfoutput>#URLEncodedFormat(mvar)#<cfoutput>">Click
Me</a>
Then, on test.cfm page:
<cfoutput>
#mvar# #URLDecode(mvar)#
</cfoutput>
You will see that values are different and the second one is
not that you passed....
Maybe you are looking for
-
I can no longer organize anything in iTunes but music since upgrading to 11.0. My photos are caught in limbo, I can sync and all end up on my computer as it should. However, there is no way to send back to the iPad the proper folders for customers
-
How to restrict Customer's of R/3 from entering CRM system.
<b>Dear SAPGurus, I have an issue at hand and hope with your guidance it can be solved. We are running CRM 4.0 and have maintained many Sales org in the system, but from a new rollout we want to restrict one newly developed sales org, Since from thi
-
Creating a pdf after upgrading to mavericks/cannot communicate with printer.
i recently upgraded to mavericks. i have office 2011 installed. when i am trying to create a pdf in word, i get an error message that says word could not communicate with the printer. however, if i print something it works. this does not happen with
-
Spotlight Doesn't Search Servers anymore?
Spotlight used to search servers attached to my computer such as backup drives I'd mount here at work but lately no matter what you search for on the drive it can't find. It comes back empty handed. What is the story here? is it a bug or something el
-
Problems with import and import recent
When I click import or import recent, Premiere says it is importing, but it doesn't. The file type is MOV and it is usually something I just captured into Premiere. If I find the file and drag it to the timeline, it works fine. Also, how can I make