Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please guide me

 
Maneesh Chauahn
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
somaraju chilukamari
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you try to type cast the parameter
 
Raghavendra Nittur
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Maneesh Chauahn
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its a statement. I tried am getting the parameter value without the encoding procedure you metioned.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic