SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with parameter with special character.

    Hello,
    From a jsp file, I call, via Javascript, another page.
    Code:
     
    url='foo.jsp?rand='+myRand+'&param1="+param1;
    alert("url="+url);
    
    document.forms[0].action=url;
    document.forms[0].submit();
    The alert shows that the url is correctly built.
    Now, int the foo.jsp file, I have:
    Code:
    String param1= request.getParameter("param1");
    System.out.println("param1="+param1);
    THe problem is that "param1" contains the special character #.
    So, when foo.jsp gets the parameter, it does not get it entirely but till it sees the # !!!

    How can I get round this problem?

    Thanks

  2. #2
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi celia,

    No matter what you do, you'll probably need to first encode the parameter when building the URL with either escape() or encodeURIComponent().

    I'm not sure if JSP's request object has a decodeURI function (or something like it), but it may possibly automatically decode the query string. If not, you'll need to find (or write!) an appropriate decoder function.

    Either way, the first step is a must.

    Good luck!
    A.P.

    generatedata.com - free JS/PHP/MySQL random test data generator.
    Form Tools - free PHP/MySQL form processor.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •