Problem in URL Encoding  in J2ME

Hi,
I have a problem in URL Encoding in J2ME. As i read thru the J2ME APIs, i found that J2ME doesn't support it.
Or can i use the URL Encoding in J2SE to modify and put into J2ME?
Or someone out there have done such coding?
Reply me!
Thanks!...

like this:
public static String URLEncoder(String str) {
if (str == null) return null;
StringBuffer resultStr = new StringBuffer( str.length() );
char tmpChar;
for( int ix=0; ix<str.length(); ix++ ) {
tmpChar = str.charAt( ix );
switch( tmpChar ) {
case ' ' : resultStr.append( "%20" );
break;
case '-' : resultStr.append( "%2D" );
break;
case '/' : resultStr.append( "%2F" );
break;
case ':' : resultStr.append( "%3A" );
break;
case '=' : resultStr.append( "%3D" );
// System.out.println( "tmpChar = '=' " + "add %3D " );
break;
case '?' : resultStr.append( "%3F" );
// System.out.println( "tmpChar = '?' " + "add %3F " );
break;
case '#' : resultStr.append( "%23" );
break;
case '\r' : resultStr.append( "%0D" );
break;
case '\n' : resultStr.append( "%0A" );
break;
default : resultStr.append( tmpChar );
break;
return resultStr.toString();
}

Similar Messages

  • Problem with URL encoding conversion

    Hi all,
    I am working on an I18N application and in my application one component sends the request to another component and then this component fetch that requet and extract the query-parameters from the request (HTTP request).
    Now the problem is that the input to first component can be given in one of the 5 character encodings:-
    UTF-8
    Shift_JIS
    EUC_JP
    Windows-31J
    ISO-2022-JP
    I have created a test program that convert the encoded URL from one character encoding to another character encoding. It is working successfully for the above 4 encodings but for the last encoding that is "ISO-2022-JP" this fails. The test programs is: -
    import java.io.*;
    import java.util.*;
    import java.net.URLDecoder;
    import java.net.URLEncoder;
    class JPtoUTF8{
         public static void main(String[] args){
              try{
                  String shift_jis = "%82%C8%82%A4%82%8B%82%E8";          // This is Shift_JIS encoded URL
                  String iso2022jp = "%1B%24B%24J%24%26%23k%24j%1B%28B";  // This is ISO-2022-JP encoded URL
                  String utf8 = "%E3%81%AA%E3%81%86%EF%BD%8B%E3%82%8A";   // This is the result that should be obtained
                  String decodedShift_jis = URLDecoder.decode(shift_jis,"Shift_JIS");
                  String decodedIso2022jp = URLDecoder.decode(iso2022jp,"ISO-2022-JP");
                  String encodedShift_JIS = URLEncoder.encode(decodedShift_jis,"UTF-8");
                  String encodedIso2022jp = URLEncoder.encode(decodedIso2022jp,"UTF-8");
                   System.out.println("shift_jis        = "+shift_jis);
                   System.out.println("encodedShift_JIS = "+encodedShift_JIS);
                   System.out.println("iso2022jp        = "+iso2022jp);
                   System.out.println("encodedIso2022jp = "+encodedIso2022jp);
              }catch(Exception e){
                   e.printStackTrace();
    }I am using jdk5 for this application.
    Please give your valuable suggestions.
    Thanks in advance.

    Could the cause be that ISO-2022-JP is not just ISO-2022-JP:
    http://www.w3.org/TR/japanese-xml/#AEN28427904
    Maybe what you are getting is one of the flavors, while the java urldecoder uses another flavor? Or maybe the string you are getting is incorrectly encoded to being with (might have been incorrectly converted from shift-jis)?
    With the shift-in shift-out design it is a difficult encoding to deal with under the best of circumstances, so you have my sympathy.

  • Hi, how to use URL encoding in jsp

    hi, how to apply URL encoding in jsp for a string, could u pls suggest some ideas to use URL encoding in jsp
    thank you in advance

    hi, thnx for the reply, but my problem is to use url encoding method
    i would u like to know how to represent in jsp program i have asp code some thing like this
    href='/project/tel_number.asp?team=<%=DbRecTeam("id")%>&name=<%=Server.URLEncode(DbRec("name"))%>'
    i would like to know how replace that Server.URLEncode stmt in jsp, could u pls suggest some equivalent method for the above stmt
    thanx in advance

  • XML to URL Encoded (XSLT?)

    I have some data in a Document object and need to convert it to URL encoded format so, for example this:
    <share>
    <code>GSK</code>
    <price>13.34</price>
    </share>
    becomes something like...
    &code=GSK&price=13.34& ...
    I've been looking into doing this with XSLT but have run into difficulties. Do you think this is the best way of solving this problem, or is there another easier way?
    Thanks.

    I did something similar, basically takes a incoming XML file and output a HTML with certain link containing XML element value as query string. One of the things you have to be careful is, like Dr. Clap mentioned, to properly encode the value. I accompolished by using java extension in my XSL.
    For example:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
              xmlns:encode="java.net.URLEncoder"
              extension-element-prefixes="encode"
              version="1.0">
         <xsl:template match="/">
              <xsl:variable name="myURL" select="concat('?blah=', encode:encode($myValueFromXML))" >
         </xls:template>
    </xsl:stylesheet>

  • URL Encoding and UTF8

    Hello Friends,
    I have been working on this problem for some time now. I have a web page that has forms fields like first name, last name etc. and then posts the data back to a servlet that writes it into a file that is utf-8 encoded. The web page has charset specified as utf-8. I was assuming that data would be sent back in the url as utf-8. I entered some japanese data copied from a japanese web page. When I looked at the file into which the form data was written I saw that it wasn't even close to utf-8 or unicode encoding of the data I had posted. For eg. I entered a japanese character: '\u4F1A' which is utf-8 encoded as 'E4 BC 9A'. But the data written into the file is '25 45 34 25 42 43 25 39 41'. This is of course because the data is url encoded which is '%E4%BC%9A', since 45 is hex for E, 34 is hex for 4 and so on. Now the question is how is it that I proceed to get the right utf data back. I am using a jrun server. Is there something that I need to set here in order to get the right characters back.

    The UTF-8 encoded sequence of bytes of the character '\u4F1A' is {-E4, -BC, -9A}, and the character '-' is (char)0x2d instead of (char)0x25. And I suppose 25 should be 2d.

  • URL Encoder not working in Netscape

    Hi All,
    I am using url encoding in my servlet for redirecting a request. The query string values has some spaces in them. The code I have used is shown below
    String mname = "Jason Perry"
    response.sendRedirect
    ("http://194.216.8.238:8081/merchant/merch.merchant?msgid=RP&mctid=1111242&totcp="+price.toString()+"&mname="+URLEncoder.encode(mname)+"&mtxnid=UY675432");
    Please note that 194.216.8.238:8081 is an IP of another server located outside our network.
    In Netscape the url is shown as http://194.216.8.238:8081/merchant/merch.merchant?msgid=RP&mctid=1111242&totcp=15
    &mname=Jason Perry&mtxnid=UY675432
    The space is not getting replaced with the plus.
    But I have observed that if the redirection is to the same server on which the servlet is running, it works fine.
    I am at loss as to why url encode is not working when routing the request to another server. I am using Netscape 4.77 .
    This is works in IE fine.
    Your inputs are appreciated.
    Thanks
    Malini

    Yeah had this problem before, use the java.net.URLEncoder class:
    <%@ page language="java" import="java.net.URLEncoder"%>
    <%
    String url = "http://194.216.8.238:8081/merchant/merch.merchant?msgid=RP&mctid=1111242&totcp=15
    &mname=Jason Perry&mtxnid=UY675432"
    String encodedUrl = URLEncoder.encode(url);
    response.sendRedirect(encodedUrl);
    %>

  • Apache plugin url encoding

    the following is on HP Apache-based Web Server/1.3.26
    with the mod_wl.so from 6.1 sp3 proxying to a 6.1 sp3 backend and I tried setting
    up QueryFromRequest ON to no avail.
    I am having the following problem with the BEA proxy plugin for Apache. I have
    a very simply scenario to demonstrate it. Lets say that you have the following
    directory/file structure:
    /applications
         /DefaultWebApp
              spaceLink.htm
              /space demo
                   resource.htm     
    NOTE: There is a "space" in the "space demo" directory name.
    Now, spaceLink.htm has a link to the file resource.htm in the "space demo" directory.
    Here is the html:
    <html> <body> click here </body> </html>
    Now assume that apache is sitting in front of this BEA box and proxying requests
    to the BEA box.
    If the Apache-BEA proxy plugin is proxying the request to BEA, then the request
    is made correctly from the browser to the proxy as:
    GET /space%20demo/resource.htm HTTP/1.1
    Notic the browser is correctly URL encoding the request.
    BUT, the apache-BEA proxy plugin is incorrectly proxying the request to the BEA
    box:
    GET /space demo/resource.htm
    Notice the Apache-BEA proxy is not URL encoding the request, so when BEA gets
    it he thinks this is a request for "/space" and "demo/resource.htm" is the http
    version.
    This problem DOES NOT happen if I use the generic http proxy module provided with
    Apache.
    Has anyone seen this problem before?
    Please get back to me if you have some information.
    Thanks,
    Cole Crawford
    Paymentech

    the following is on HP Apache-based Web Server/1.3.26
    with the mod_wl.so from 6.1 sp3 proxying to a 6.1 sp3 backend and I tried setting
    up QueryFromRequest ON to no avail.
    I am having the following problem with the BEA proxy plugin for Apache. I have
    a very simply scenario to demonstrate it. Lets say that you have the following
    directory/file structure:
    /applications
         /DefaultWebApp
              spaceLink.htm
              /space demo
                   resource.htm     
    NOTE: There is a "space" in the "space demo" directory name.
    Now, spaceLink.htm has a link to the file resource.htm in the "space demo" directory.
    Here is the html:
    <html> <body> click here </body> </html>
    Now assume that apache is sitting in front of this BEA box and proxying requests
    to the BEA box.
    If the Apache-BEA proxy plugin is proxying the request to BEA, then the request
    is made correctly from the browser to the proxy as:
    GET /space%20demo/resource.htm HTTP/1.1
    Notic the browser is correctly URL encoding the request.
    BUT, the apache-BEA proxy plugin is incorrectly proxying the request to the BEA
    box:
    GET /space demo/resource.htm
    Notice the Apache-BEA proxy is not URL encoding the request, so when BEA gets
    it he thinks this is a request for "/space" and "demo/resource.htm" is the http
    version.
    This problem DOES NOT happen if I use the generic http proxy module provided with
    Apache.
    Has anyone seen this problem before?
    Please get back to me if you have some information.
    Thanks,
    Cole Crawford
    Paymentech

  • Problem when setting encoding to ISO-8859-1

    Hi. Is there something I'm missing when it comes to setting
    encoding? Here are the code in the mxml:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    </Application>
    In the html-template I'm setting:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=ISO-8859-1" />
    The code for sending data from the app:
    <mx:HTTPService
    id="service"
    url="encoding.jsp"
    method="post"
    showBusyCursor="true"
    result="onResult(event)"
    resultFormat="xml"
    contentType="application/xml"
    fault="onFault(event)"
    useProxy="false" />
    public function send():void {
    var xml:XML = <Data>{data.text}</Data>;
    service.send(xml);
    But still the respons jsp I have made says it receives the
    data in UTF-8 format? What am I doing wrong?
    Servercode:
    don't work: BufferedReader reader = new BufferedReader( new
    InputStreamReader( is ) );
    work: BufferedReader reader = new BufferedReader( new
    InputStreamReader( is, "UTF-8") );

    Are there no-one who have the same problem? I've tried
    everything imaginable, and still the serverside receives the data
    as UTF-8.
    Is it supported at all to set the encoding of the
    request?

  • Sending document to oracle xml gateway web service and body is url encoded

    Hello,
    a question from a complete newbie to web services. I have some code that is sending a soap message to an oracle xml gateway web service. In the soap message the values in the soap body look like &lt ;CNTROLAREA&gt ;
    when I would be expecting <CNTROLAREA>. What I have been told is that the content of the ReceiveDocument element has been url encoded which causes the &lt and to correct it I need to change the paramater type from object to xmlnode and to build the request as an xmldocument. The xmlnode and xmldocument comes from a .net guy so I've been trying to find the equivalent in java but am not having any luck. I have a lot of reading to do but was wondering if someone might be able to point me in the right direction on how to correct the problem. I captured the soap message being sent using tcpmon. Why does the body have the &lt instead of the < as I was expecting and is there an xmldocument type? The header part of the soap message looks as I expect. "><soapenv:Header><ns1:XMLGateway_Header xmlns:ns1="http://xmlns.oracle.com/apps/fnd/XMLGateway"><ns1:MESSAGE_TYPE>XML</ns1:MESSAGE_TYPE>. It is being sent as a com.oracle.xmlns.apps.fnd.XMLGateway.XMLGateway_Header type.
    thanks
    Thanks
    Edited by: twf123 on May 5, 2010 11:59 AM
    Edited by: twf123 on May 5, 2010 12:00 PM

    twf123 wrote:
    What I have been told is that the content of the ReceiveDocument element has been url encoded which causes the &lt and to correct it I need to change the paramater type from object to xmlnode and to build the request as an xmldocument. Where do you change the parameter type?
    The xmlnode and xmldocument comes from a .net guy so I've been trying to find the equivalent in java but am not having any luck. How do you get the data from .net guy? Which interface do you use? What processing do you do after receiving the data?

  • URL encoding special characters in episode name

    Hello,
    Configuration :
    1 capture agent on a MAC MINI under MAC OS X 10.6.5
    1 PCP2 server on an XServe under MAC OS X 10.6.5
    I encounter this problem since 10.6.5 update :
    When I stop a Podcast capture, if episode name is for example abcd#, '#' character is "URL encoded" to '%23' sequence. So the final file name of the podcast is abcd%23.m4v instead of abcd#.m4v.
    This was not the case under 10.6.4.
    I tried this solution : renaming the file adding a task in the workflow ; this task launches a bash script which renames all files replacing '%23' sequences by a '#' character.
    Files are well renamed, but the task don't give hand back, and XGrid task never ends.
    Got this error in /var/log/system.log :
    sandbox [nnn] : bash(12146) : deny file-ioctl /path/to/bash-script
    Thanks for help

    Problem solved !
    I had a problem with rights on my podcasts directory.
    So, for those who are interested, you can add a task to your workflow, for example a bash batch file which renames all files in your podcast directory whose name contains a special character :
    for fic in `ls`
    do
    mv $fic `echo $fic | sed -e s/%23/#/g`
    done
    the additional workflow task must contain 2 items :
    --- an item "command" of type String with the path of your batch file as value
    --- an item "dependsOnTasks" of type array with an element of type string with "postflight" as value

  • URL ENCODING

    hi,
    I am devoloping using JSP pages and servlets on JRUN web server. I found that when the browser passes the URL (along with my custom parameters) to the servlet, it encodes any spaces in my parameter values with '%20'. Now am I correct that this is done using Base64encoding?? However, I am not using any encoding mechanism and this automatic conversion seems to cause a problem in that the web server thinks that it needs to authenticate this URL and is unable to process it. Does anyone know how I can turn this encoding off and pass any spaces in my parameter values as they are, or is there any other known solution to this.
    Any help will be much appreciated.
    Thanks

    hi,
    I am devoloping using JSP pages and servlets on JRUN
    web server. I found that when the browser passes the
    URL (along with my custom parameters) to the servlet,
    it encodes any spaces in my parameter values with
    '%20'. Now am I correct that this is done using
    Base64encoding?? All browsers will do this, and it's called "URL encoding". It's a little trick to use other characters than simple letters and digits in URLs (including parameters). This has nothing to do with Base64 encoding.
    However, I am not using any encoding
    mechanism The browser uses this encoding, and you (the server) cannot do anything about it. It shouldn't actually be a problem at all.
    and this automatic conversion seems to cause
    a problem in that the web server thinks that it needs
    to authenticate this URL and is unable to process it.I think you're making a mistake here. URL encoding has nothing to do with URL authentication. I guess you mean that the webserver is requesting username/password ? Then you have configured the requested URL to be authenticated at yuor webserver.
    Does anyone know how I can turn this encoding off and
    pass any spaces in my parameter values as they are, or
    is there any other known solution to this.You really don't want to turn URL encoding off. Next, it can't be 'turned off'. Jrun will automatically decode the %20 to a space again; you won't notice it has been encoded at all.
    Your problem must be somewhere else. Have a close look at your http authentication settings...
    >
    Any help will be much appreciated.
    ThanksNo problem
    Cheers,
    Tom

  • H:outputlink stop url encoding

    Hi, I have a simple outputlink like this:
    <h:outputLink value="#{myBean.myUrlFile}"/>the problem is that myUrl file can contains characters like é, à, I know this is not very a good idea but I had to deal with it.
    When the JSF is parsed a link like this is created:
    <a href="/R%E9glement.pdf"></a>I'd like that jsf don't encode the link beacause like it is not valid.
    Like this it is valid:
    <a href="/Réglement.pdf"></a>any idea?
    Thx

    But this link is used file, like a pdf file for exemple.So?
    This file can be uploaded and so can contains characters like é à ù etcThat has nothing to do with how the URL is encoded.
    What I don't understand is when the link is encoded, file is not found => 404 error.It means Not Found. Again that has nothing to do with URL-encoding.
    when the link is not encoded (so as you've said with a bad format) the file is found.Then you have a co-operating bug. Your server should be URL-decoding the URL. What is your server exactly?

  • Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containin

    Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs. at Error$/throwError() at flash.net::URLVariables/decode() at flash.net::URLVariables() at flash.net::URLLoader/onComplete() _________________________________________________________________________________________ ____________ stop(); var DepartVars:URLVariables = new URLVariables(); var DepartURL:URLRequest = new URLRequest("scripts/www.mywebsite.com/depart.php"); DepartURL.method = URLRequestMethod.POST; DepartURL.data = DepartVars; var DepartLoader:URLLoader = new URLLoader; DepartLoader.dataFormat = URLLoaderDataFormat.VARIABLES; DepartLoader.addEventListener(Event.COMPLETE, completeDepart); depart_btn.addEventListener(MouseEvent.CLICK, DepartUser); // Function to run when the Depart button is pressed function DepartUser (event:MouseEvent):void{             // Ready the variables here for sending to PHP           DepartVars.post_code = "Depart";         // Send the data to the php file           DepartLoader.load(DepartURL);         welcome_txt.text = "Processing request...Bon Voyage"; } // Close DepartUser function /////////////////////////////////////// // Function for when the PHP file talks back to flash function completedepart(event:Event):void{     if (event.target.data.replyMsg == "success") {             var refreshPage:URLRequest = new URLRequest("javascript:NewWindow=window.location.reload(); NewWindow.focus(); void(0);");             navigateToURL(refreshPage, "_self");         } // Close completeDepart function ////////////////////////////// // Code for the View res Button var viewRes:URLRequest = new URLRequest("view_res.php"); viewRES_btn.addEventListener(MouseEvent.CLICK, viewResClick); function viewResClick(event:MouseEvent):void {     navigateToURL(viewRes, "_self"); } ///////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // Code for the Edit Res profile Button var editRes:URLRequest = new URLRequest("edit_res.php"); editRES_btn.addEventListener(MouseEvent.CLICK, editResClick); function editResClick(event:MouseEvent):void {     navigateToURL(editRes, "_self"); } }

    I have a similar problem
    whey I use .txt my code works, but when I change to .dat external file, it get error 1067
    my code:
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
    var loader: URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, loading);
    loader.load(new URLRequest("rssnews.dat"));
    function loading(e: Event): void {
              news_1.text = trace(e.target.data.titulo);
              news_2.text = trace(e.target.data.texto);

  • Unescaping URL Encoded Strings

    Anyone know how to unescape URL encoded strings using XSL? I can use the translate() function to replace the + signs with spaces but the %3F and %3E style characters are causing problems. The escaped characters are in an XML doc.
    Any help would be appreciated.

    Anyone know how to unescape URL encoded strings using XSL? I can use the translate() function to replace the + signs with spaces but the %3F and %3E style characters are causing problems. The escaped characters are in an XML doc.
    Any help would be appreciated.

  • Reverse the url-encoded process

    Hi there,
    Is it possible to flash rebuild a string that as been
    url-encoded?
    Thanks,

    Hi David thanks for your reply.
    It seems that my problem is not url-encoded.
    I have a flash with a sendAndLoad vars to a coldfusion file.
    The coldfusion is suppose to return a XML object. Instead it
    returns a
    String because the XML special characters [ <, >, " ]
    are converted to
    [&lt;, &gt;, &quot;].
    I think this problem is because you can have a programming
    language based on
    tags directly written in coldfusion (also a programming
    language based on
    tags). Like when you write html formatting text in an xml
    structure. The xml
    structure will assume tags like <br/> as a child Node
    instead of a tag
    content.
    So I had to make some functions to replace special characters
    in a string.
    I don't agree with this solution, but it was the only thing I
    came up with.
    Thanks
    "David Stiller" <[email protected]> wrote in
    message
    news:e63u3m$oug$[email protected]..
    > SteveStall,
    >
    >> Is it possible to flash rebuild a string that as
    been url-encoded?
    >
    > You betcha. The escape() function url-encodes strings;
    the unescape()
    > function url-decodes strings.
    >
    >
    > David
    > stiller (at) quip (dot) net
    > Dev essays:
    http://www.quip.net/blog/
    > "Luck is the residue of good design."
    >

Maybe you are looking for

  • Cost of restore 10.3 disk

    what is the cost of a restore disk for Panther 10.3

  • Email button created in InDesign won't work on Interactive PDF. Anyone know a fix?

    Hello there, I am trying to make a e-mail button work after its .swf file is imported into a new iD document and exported as a interactive PDF. I have tried various things and work around but I can not seem to be able top make it wrong. I ask iD twit

  • Date to number conversion?

    I want to select a number of rows created within last week. To do it I use a select statement with: WHERE sysdate-o.created_on <= days; (days is a number, created_on is a date) Everything works fine, but I get warnings like this one: PLW-07204: conve

  • Help...cant find my music

    I love(d) my ipod and everything was going really well until my little girl got a new computer for Christmas. Tonight she has tried to download somthing from her new machine on to my ipod and now I can only access the new stuff she has downloaded (an

  • Macbook Pro Retina Display problems.

    Hi I recently purchased the Macbook Pro with Retina Display. I noticed that there is a verticle line running from each side of the screen. I doesn't seem to affect the display quality. I just wanted to know if anyone else has it and if it could lead