# and other special characters in querystring - JSP

Discussion in 'Java' started by Hemaraj, Aug 22, 2007.

  1. Hemaraj

    Hemaraj Guest

    Dear Java group

    I have a JSP page which has some hyperlinks that contain values such as

    http://www.mydomain.com#Something1
    http://www.mydomain.com#Something2

    When I click on them, they should be passed as value of query string to a
    servlet. When the servlet is run, I can see in url field of the browser that
    the correct value was passed ; for example I see:


    http://localhost:8080/MyWebSite/ShowDetails?SelectedItem=http://www.mydomain.com#Something2



    Where ShowDetails is the name of the servlet that is getting this selected
    item through

    String Selected1 = request.getParameter("SelectedItem");



    However, when I want to display this field using

    out.println("<p>Value " + Selected1 + "</p>");



    I only see http://www.mydomain.com - what I want to see is :
    http://www.mydomain.com#Something2 - meaning, the part #something1 is not
    there anymore.

    How to solve this problem?

    Thank you
    Hemaraj, Aug 22, 2007
    #1
    1. Advertising

  2. Hi Hemaraj,

    the #-part is interpreted by the browser and not sent to the server. It
    might appear in the URL line, however only the part before the # will be
    passed to the server. You will have to URL-encode the string that you put
    into the link if you want to send that information to the server. However
    then the browser will not jump to the anchors anymore. To achieve both one
    could hack:

    http://www.mydomain.com#Something1#Something1

    You would have to create some magic servlet mapping to make that work. I
    wonder, though why you would want to send the anchor part to the server in
    that URL instead of adding it to a parameter:

    http://www.mydomain.com?anchor=Something1#Something1

    Hope that helps.

    Best regards,
    Jan


    Hemaraj wrote:

    > I have a JSP page which has some hyperlinks that contain values such as
    >
    > http://www.mydomain.com#Something1
    >
    > When I click on them, they should be passed as value of query string to a
    > servlet.
    > I only see http://www.mydomain.com - what I want to see is :
    > http://www.mydomain.com#Something2 - meaning, the part #something1 is not
    > there anymore.


    --
    _________________________________________________________________________
    insOMnia - We never sleep...
    http://www.insOMnia-hq.de
    Jan =?UTF-8?B?VGhvbcOk?=, Aug 22, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Mueller
    Replies:
    3
    Views:
    32,954
    Stefan Mueller
    Jul 23, 2006
  2. Replies:
    0
    Views:
    4,332
  3. Replies:
    2
    Views:
    1,070
    Ingo Menger
    May 31, 2007
  4. rvino
    Replies:
    0
    Views:
    4,635
    rvino
    Aug 14, 2007
  5. majna
    Replies:
    4
    Views:
    639
    Thomas 'PointedEars' Lahn
    Sep 19, 2007
Loading...

Share This Page