The # character has meaning in a URL, it denoted a named anchor. E.g.:
So the query
string runs from the ? to the # and not beyond. If your pid can include # character you will need to URLEncode it. Have a look at the java.net package
you should see a way of doing this.