Solved

How to pass double byte value in Javascript

Posted on 2010-09-21
27
384 Views
Last Modified: 2012-05-10
HI ,

How to pass double byte values in java script ,

I tried this 2 way but not usefull
 var url="<%=request.getContextPath()%>/qtyCheck.do?HatsudenNo='"+HatsudenNo+"'";
or
 var url="<%=request.getContextPath()%>/qtyCheck.do?HatsudenNo="+HatsudenNo;

I will get Junk values in my action class .
If i use escape () then i will give give null ..........



0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 12
27 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 33725527
Was useful to know your Junk values...

Try to use : .Replace("\\","\\\\")
And encodeURI : http://www.w3schools.com/jsref/jsref_encodeURI.asp


var url = "<%= request.getContextPath().Replace("\\","\\\\") %>/qtyCheck.do?HatsudenNo=" + encodeURI(HatsudenNo);

Open in new window

0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33725676
'<%=request.getContextPath().Replace("\\","\\\\")%>/qtyCheck.do?HatsudenNo='+encodeURI(HatsudenNo);
 
i change like this... but it wont work??
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33725909
sorry I was thinking you're using the .NET framework...

Try :


var url = "<%= request.getContextPath().replaceAll("\\","\\\\") %>/qtyCheck.do?HatsudenNo=" + encodeURI(HatsudenNo);

Try this too :

var url = "<%= request.getContextPath().replaceAll("\\","") %>/qtyCheck.do?HatsudenNo=" + encodeURI(HatsudenNo);
alert(url);

Open in new window

0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33726822
both give 500 error only ....
@leakim971: can you tell why we want to replace ??
 
with out give replaceAll its goes to Action calss but in that class its give null value ?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33728631
>can you tell why we want to replace ??
I'm staying on .NET where the backslash are escaping the characters...

0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33728776
If is use encodeURI() where i will decode that??
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33728869
>If is use encodeURI() where i will decode that??

not needed, it's used to sent the data correctly
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33732319
Any update ??
0
 
LVL 11

Expert Comment

by:Manish
ID: 33732346
Is this junk? HatsudenNo
how you are getting it?
If it is from request , u can use java to encode it or directly pass it to javascript excape method.
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33733369
>> Is this junk? HatsudenNo
No its Double byte letter .
>>> how you are getting it?

if the user enter double byte value onchange that time i call some javascript function ,
 
How can we endoe , that's java script value ??
if i use escape() then in action class i get only null value ..
 
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33734423
>if the user enter double byte value

What do you call double byte value on the client side ? It came from an input textbox ?
Thanks @karanw for your questions.
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33734960
>>>What do you call double byte value on the client side ? It came from an input textbox ?
Our client is Japaneses so they can enter double byte value in text box
refer the image below

2bytealert.JPG
singlebytealert.JPG
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33735068
What is the current charset of your page(s) ? utf-8 ?
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33735142
Ya UTF-8 only
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33735191
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33735350
ya thats gd link .. but while passing from javascript to jsp thats the pblm alert msg are coming clear only ....
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33735451
Could you confirm if you alert immediately (without posting to a jsp page) the url variable you get the japanese char  ?
In your previous image I was thinking it's not the case.
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33735513
ya without post the jsp i get that alert
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33735578
Another test, do you get the alert and the encoded char with :

var url = "<%= request.getContextPath()%>/qtyCheck.do?HatsudenNo=" + encodeURI(HatsudenNo);
alert(url);
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33735585
This is my script code
function checkAlNo(i)
			{
			    
		
                initRequest();
				
				var HatsudenNo= document.getElementById(("HatsudenNo")+i).value;
				alert(HatsudenNo);
			    var url="<%=request.getContextPath()%>/qtyCheck.do?HatsudenNo="+HatsudenNo;
			    alert(url);
			    xmlhttp.open("GET", url, true);
			    xmlhttp.setRequestHeader("Content-Type", contentType);
			    xmlhttp.onreadystatechange =  function(){ checkQty(i); };
			    xmlhttp.send();
			
			}

			function checkQty(i)
			{
				
				var returnVal=false;	
				  if(xmlhttp.readyState == 4)
				  {
				    var rText = xmlhttp.responseText;

				    document.getElementById(("HatsudenNo")+i).value=rText;
				  
				  
				     returnVal=true;
				  
				    
				  }
				  return returnVal;
			}

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 33735661
Ok please confirm for the second alert you have the chars encoded
function checkAlNo(i) {
                initRequest();
				var HatsudenNo= document.getElementById(("HatsudenNo")+i).value;
				alert(HatsudenNo);
			    var url="<%=request.getContextPath()%>/qtyCheck.do?HatsudenNo=" + encodeURI(HatsudenNo);
			    alert(url); // the japanese chars should be encoded !
			    xmlhttp.open("GET", url, true);
			    xmlhttp.setRequestHeader("Content-Type", contentType);
			    xmlhttp.onreadystatechange =  function(){ checkQty(i); };
			    xmlhttp.send();
			
			}

			function checkQty(i)
			{
				
				var returnVal=false;	
				  if(xmlhttp.readyState == 4)
				  {
				    var rText = xmlhttp.responseText;

				    document.getElementById(("HatsudenNo")+i).value=rText;
				  
				  
				     returnVal=true;
				  
				    
				  }
				  return returnVal;
			}

Open in new window

0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33735666
Its giving like this
alertURL.JPG
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 33735713
I dont know whether its its correct encoding or not
ABCD in java class i getting like this  
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33735768
>Its giving like this
It's a good news !

>ABCD in java class i getting like this
depend, what do you want to do with ? put this in the database ?
0
 
LVL 20

Author Closing Comment

by:Sathish David Kumar N
ID: 33735850
Thanks Man,

I did  String ss=new String(sText.getBytes("ISO-8859-1"),"UTF-8");
convertion like this in java

that code work well ......

Thank you soo much .. kindly help
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33735878
You're very welcome! Thanks for the points!
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 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