Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hash symbol # problem in URL

 
Esther Kak
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP page which has a ahref="http://www.abcXXXX.com/privacy.jsp#aaa"

Problem: When I click on the ahref, everything from # is stripped off in the URL
  • Try 1: Encoded # with %23 - did not work
  • Try 2: Used Java URL encoder class to encode


  • Try 1 & 2 are not working. Is there are way around to make this work.
     
    Paul Clapham
    Sheriff
    Posts: 21107
    32
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    When you say "doesn't work", do you mean your JSP generates HTML that contains an anchor named "aaa" and the browser fails to scroll to it? Or did you expect something else to happen? If so, what?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64833
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This has nothing to do with JSP, so it's been moved to the HTML forum (where a duplicate post has already been closed).
     
    Esther Kak
    Ranch Hand
    Posts: 51
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    In my JSP I hardcoded the URL for ahref in Try1 - Result is everything from # has been stripped off.

    In try2, I used URLEncoder to store the encoded value in a string object and assigned the value to ahref like this

    String learnURL = "http://www.abcXXXX.com/privacy.jsp"+URLEncoder.encode("#aaa");

    ahref=<%=learnURL%>

    It encodes # to %23 but it is not going where it is supposed to.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64833
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you are trying to use the # as an anchor, then encoding the character will simply make it not work (since you've changed the expected character).

    Rather you need to find out what's going on with using it normally.

    So you are saying that when you have something like:

    and you click on the link, that the "xyz" is stripped?

    Are you sure? It works fine for me in all browsers that I tried.

    Have you verified that the syntax of the <a> tag is really what you think it is?
    [ February 05, 2008: Message edited by: Bear Bibeault ]
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This is a case where either the LiveHTTPHeaders or the FireBug plugin for Firefox comes in really handy.

    With it, you'll be able to tell if the browser, or the server is stripping your characters out of the querystring. You'll also be able to find out if a request to the server is even being made (if you're already on the target page, the browser never makes a request to the server, it just moves to the specified anchor).
     
    Eric Pascarello
    author
    Rancher
    Posts: 15385
    6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Are you trying to read the hash part on the client or on the server?

    Eric
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic