This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Please guide me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Please guide me " Watch "Please guide me " New topic
Author

Please guide me

Maneesh Chauahn
Ranch Hand

Joined: Mar 06, 2006
Posts: 48
Hi All,
I have a url as shown below
http://localhost/host/page.do?abc=#5

Now i want to get the parameters values in the action class like this

String parameter = request.getParameter("abc");

When i checked String parameter value it contains empty string.

If is possible to get value then how to get the values of the parameters from the URL whose value is started from #

Thanks
Maneesh Chauhan
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You will have to encode the url. For example, Java provides methods like encodeURL or encodeRedirectURL. You'll find the same in JSTL, using param tags int the url tag.


[My Blog]
All roads lead to JavaRanch
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Hi Maneesh,

If you don't find out of your context, I got a small doubt...

Where this URL supposed to go, i mean without any port number!
If we don't specify the Port then it will go to HttpServer(80). but how can it reach /page?

http://localhost/host/page.do?abc=#5


Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
somaraju chilukamari
Greenhorn

Joined: Feb 21, 2007
Posts: 3
you try to type cast the parameter
Raghavendra Nittur
Greenhorn

Joined: Feb 19, 2007
Posts: 29
Originally posted by Srinivasan thoyyeti:
Hi Maneesh,

If you don't find out of your context, I got a small doubt...

Where this URL supposed to go, i mean without any port number!
If we don't specify the Port then it will go to HttpServer(80). but how can it reach /page?

http://localhost/host/page.do?abc=#5



I agree with you. # in begining doesn't matter.

Hi Maneesh,

give port number, 8080 after localhost.

i mean http://localhost:8080/host/your welcome page name

Regards, Raghav
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
It's got nothing to do with encodeURL/encodeRedirectURL (which are used for handling URL rewriting in the presence of HTTP sessions) or a missing port (which would lead to an error like "can't find host").

The "#" character separates the URL parameters from the fragment (which in this case is "5"). If the "#" is actually part of the parameter, then the URL needs to be encoded by the java.net.URLEncoder.encode method. Afterwards it will look like "http://localhost/host/page.do?abc=%235", which means the "#" has been replaced by its hexadecimal equivalent, and is no longer interpreted as a special URL character.
[ March 15, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Maneesh Chauahn
Ranch Hand

Joined: Mar 06, 2006
Posts: 48
Hi
I am agree that i need to encode the URL and but my question is that why i should i need to encode the url . Is # character is the special meaning that browser/webserver can't process

Thanks
Maneesh
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Is # character is the special meaning that browser/webserver can't process

From a rfc:
The character "#" is unsafe and should always be encoded because it is used in World Wide Web and in other systems to delimit a URL from a fragment/anchor identifier that might follow it.

You use it when you want to jump at a particular position in a web page, like in the following link :
http://faq.javaranch.com/view?ScjpFaq#officialFaq

[ March 15, 2007: Message edited by: Satou kurinosuke ]
[ March 15, 2007: Message edited by: Satou kurinosuke ]
Raghavendra Nittur
Greenhorn

Joined: Feb 19, 2007
Posts: 29
Originally posted by Ulf Dittmer:

If the "#" is actually part of the parameter, then the URL needs to be encoded by the java.net.URLEncoder.encode method.
[ March 15, 2007: Message edited by: Ulf Dittmer ]



Hi Ulf,

without encoding URL using the java.net.URLEncoder.encode method am able to get the parameter preceeding with '#'.

Am new to Servlets & JSP please Correct me if am going wrong.

Regards, Raghav
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41132
    
  45
without encoding URL using the java.net.URLEncoder.encode method am able to get the parameter preceeding with '#'.


I'm not sure if that's a question or a statement, but it's quite easy to try both ways, and see what happens in either case.
Raghavendra Nittur
Greenhorn

Joined: Feb 19, 2007
Posts: 29
Its a statement. I tried am getting the parameter value without the encoding procedure you metioned.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please guide me
 
Similar Threads
If QueryString has # value in one of the prameter then how to get the complete URL from request
Parameter order reversed when using Mule and Axis for a web service
How to pass two parameters along with URL IN STRUTS2.X
dynamic parameters
request.getRequestURI() problem