Solved

passing a variable in the address bar

Posted on 2004-08-05
3
248 Views
Last Modified: 2010-04-01
How can I pass the variable name to the next page through the address bar? The way ive been trying will not pass anything after the blank space between the firstname and lastname

name = "adro ron";
out.print("<form name='Form1231' method='post' action="+request.getContextPath()+"/allocate_actualtime.jsp?customername="+firstnames[cnt]+lastnames[cnt]+"&names="+name+">");
Thanks
0
Comment
Question by:ram_os
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 100 total points
ID: 11725133
You need to encode the spaces into a form that browsers can handle :-)

String name = java.net.URLEncoder.encode( "adro ron", "UTF-8" ) ;
String customername = java.net.URLEncoder.encode( firstnames[cnt]+lastnames[cnt], "UTF-8" ) ;
out.print("<form name='Form1231' method='post' action="+request.getContextPath()+"/allocate_actualtime.jsp?customername="+ customername +"&names=" + name + ">");
0
 

Author Comment

by:ram_os
ID: 11726496
Thanks Tim, that worked....

Could you explain your code plz and why I needed to do it, if you dont mind,
Thanks again
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11726573
Yeah, sure :-)

You basically, can't have any special characters, spaces, "?"s, or "&"s in your parameters, as the browser will think they are gaps in the url, or the start of a parameter list or the next parameter, etc

So...

You have to encode the parameters so that they get read correctly by the browser

The way to encode things is like this:

%XX

where XX is the ascii value of the special character

So " " becomes "%20"

and URLEncoder.encode does this for you :-)

Hope you understand :-)

Glad I could help :-)

Tim
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now