aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Hash symbol #  problem in URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Hash symbol #  problem in URL" Watch "Hash symbol #  problem in URL" New topic
Author

Hash symbol # problem in URL

Esther Kak
Ranch Hand

Joined: Oct 11, 2006
Posts: 51
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
    Bartender

    Joined: Oct 14, 2005
    Posts: 18675
        
        8

    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

    Joined: Jan 10, 2002
    Posts: 61437
        
      67

    This has nothing to do with JSP, so it's been moved to the HTML forum (where a duplicate post has already been closed).


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Esther Kak
    Ranch Hand

    Joined: Oct 11, 2006
    Posts: 51
    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

    Joined: Jan 10, 2002
    Posts: 61437
        
      67

    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

    Joined: Dec 11, 2004
    Posts: 13410

    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).


    Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
    Eric Pascarello
    author
    Rancher

    Joined: Nov 08, 2001
    Posts: 15376
        
        6
    Are you trying to read the hash part on the client or on the server?

    Eric
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Hash symbol # problem in URL