Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

If QueryString has # value in one of the prameter then how to get the complete URL from request

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I am facing one problem.
I have one application say A which is being hitted from other application say B.
When someone hits the application A from B there is one URL (my application i.e A url ) get created.
So I copies all the requestParameter and uses it for processing.

But now in one of my parameter it has value whihc is having # in value e.b ABC#xyz
The problem is when I tries to get all parameters the values after # did not come through request.

I tried below all things but i did not get the complete url and thus i am stuck


Can any one came across such issue? Any common methodology to follow in this case?

Thanks in advance!!

PP.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried
HttpServletRequest.getQueryString()?
Returns:
a String containing the query string or null if the URL contains no query string. The value is not decoded by the container.

It seems to be designed to be used in conjunction with
StringBuffer getRequestURL()
[...]The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.
If this request has been forwarded using RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse), the server path in the reconstructed URL must reflect the path used to obtain the RequestDispatcher, and not the server path specified by the client.

Because this method returns a StringBuffer, not a string, you can modify the URL easily, for example, to append query parameters.

This method is useful for creating redirect messages and for reporting errors.


 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Istvan said, if A (the one being 'hit' with the HTTP request) is a Servlet, then you should use the methods he described to get the correct parts of the string, or better, use the request.getParameter(paramName) method...

But that is just part of the problem. The problem seems to be that you are not making a valid HTTP request URL from application B. You need to make sure the URL follows all the rules for URLs. One rule that you broke was the use of special characters. The # sign means something specific in a URL, so when you try to use it for anything else you break the contract and the characters can be handled differently than you expect (they may never actually reach the Servlet).

So first things first:
- Read up on the HTTP protocol and make sure the URL you build follows the rules, and understand what the different characters mean.

Then, you are going to understand that the #, and other special characters may end up in the data you want to send over the URL, so how do you fix that? The answer is to 'encode' the strings:
The URLEncoder class is designed just for this purpose. It identifies all the 'special characters' in the string you provide and replaces them with escape sequences. And if you do it right then you may not even have to worry about decoding it on the receiving side - it may be done for you automatically. In the situation when it is not done for you, you can use the URLDecoder class to do it yourself.
 
prash patil
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve !!
I tried those method too.
Only thing I want to check that if I am not aware of any process/method which will help me,
As my application is being accessed from other application I was trying to figure out if I can do anythin at my side.
But it seems the application A will need to change the logic so that the URL will not have specail charcters in normal format.

Once again thanks for your reply.

PP.
 
What do you have to say for yourself? Hmmm? Anything? And you call yourself a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic