Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

servlet request problem

  • 18-07-2007 7:55pm
    #1
    Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭


    Ok theres a site with an address similar to the following
    http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID&cd=0
    my servlet performs a check in the following way
    //please note request.getString is the same as request.getParameter except it
    //throws a certain exception if a string does not exist
    String view = request.getParameter("view");
    if(view= confirm)
    {
                 fileId= request.getString("id");
                 cd = request.getParameter("cd");   
    
    
    }
    

    The problem is sometimes the address needs to be of this form
    http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID&cd=0

    So when this address is entered I get an exception that the string cd doesn't exist.

    This is because of there being a "%26" instead of & before the "cd" end.

    Is there anyway I could solve this problem?


Comments

  • Registered Users, Registered Users 2 Posts: 7,541 ✭✭✭irlrobins


    You could get the parameter for for file and then if it contains the substring "%26" break it up into file and cd parts. If it doesn't then continue on to get parameter for cd as you have given above.


  • Moderators, Science, Health & Environment Moderators Posts: 10,088 Mod ✭✭✭✭marco_polo


    quinnd6 wrote:
    Ok theres a site with an address similar to the following
    http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID&cd=0
    my servlet performs a check in the following way
    //please note request.getString is the same as request.getParameter except it
    //throws a certain exception if a string does not exist
    String view = request.getParameter("view");
    if(view= confirm)
    {
                 fileId= request.getString("id");
                 cd = request.getParameter("cd");   
    
    
    }
    

    The problem is sometimes the address needs to be of this form
    http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID%26cd=0

    So when this address is entered I get an exception that the string cd doesn't exist.

    This is because of there being a "%26" instead of & before the "cd" end.

    Is there anyway I could solve this problem?

    It is the & symbol that is used to divide the query string into name=value parameters. As there is no & symbol before the cd it is not a parameter. The %26 is the url encoded symbol for an &, this is so you can put an & into a url string without it being interpreted as a parameter divider.

    What the string ?view=confirm&file=ID4793944974.ID%26cd=0

    gives you is two parameters, view="confirm" and file="ID4793944974.ID&cd=0". So as per the previous post you would have to extract it from the file parameter.

    If the string was ?view=confirm&file=ID4793944974.ID&cd=0 you would have three parameters view="confirm" and file="ID4793944974.ID" and cd="0"

    Is there any particular reason why there has to be a %26 before the cd and not an &?


  • Moderators, Science, Health & Environment Moderators Posts: 10,088 Mod ✭✭✭✭marco_polo


    irlrobins wrote:
    You could get the parameter for for file and then if it contains the substring "%26" break it up into file and cd parts. If it doesn't then continue on to get parameter for cd as you have given above.

    The "%26" would actually be an "&" in the string returned by get parameter.

    I have just had a thought that is making my head hurt a little. How would you pass the string "%26" as part of a parameter?


  • Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭quinnd6


    I think I fixed the problem using decoder and substring and indexof.

    What am I wondering about now is when the address is
    http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID&cd=0

    using URLDecoder.decode(file)

    I get ID4793944974.ID&cd=0 so the %26 is converted to an &.

    when the address is
    http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID%26cd=0

    using decoder.decode(file)
    I also get ID4793944974.ID&cd=0 for the file so %2526 also gets converted to an &.

    Why are "%25" and "%2526" both decoded to "&"?


  • Moderators, Science, Health & Environment Moderators Posts: 10,088 Mod ✭✭✭✭marco_polo


    quinnd6 wrote:
    I think I fixed the problem using decoder and substring and indexof.

    What am I wondering about now is when the address is
    http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID%26cd=0

    using URLDecoder.decode(file)

    I get ID4793944974.ID&cd=0 so the %26 is converted to an &.

    when the address is
    http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID%2526cd=0

    using decoder.decode(file)
    I also get ID4793944974.ID&cd=0 for the file so %2526 also gets converted to an &.

    Why are "%25" and "%2526" both decoded to "&"?

    You jus helped me figure out my previous question. %25 is the url safe encoding for the % charachter. I am guessing something like the folowing happens when you enter %2526:

    %2526
    (%25)26
    %26
    (%26)
    $


  • Advertisement
Advertisement