Solved

passing a variable in the address bar

Posted on 2004-08-05
3
251 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Set up Wildfly 10 8 392
Using Tomcat as raspberry pi java app server 13 164
thymeleaf natural templating vs JSP 2 95
Why my table column Id is not passed to java object? 4 38
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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