Solved

passing a variable in the address bar

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Display the newly inserted values 3 74
tomcat users xml 7 106
Spring MVC - sending raw charset to backend 3 190
How to Post an If Statement in JSP 3 51
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Knowledge base software has turned out to be a quite reliable method for storing information, promoting collaborative work and for sharing valuable input and solutions.However, some organizations are trying to develop a knowledge base that works wit…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

27 Experts available now in Live!

Get 1:1 Help Now