Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

How to pass double byte value in Javascript

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
Sathish David  Kumar N
Asked:
Sathish David  Kumar N
  • 13
  • 12
1 Solution
 
leakim971PluritechnicianCommented:
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
 
Sathish David Kumar NAuthor Commented:
'<%=request.getContextPath().Replace("\\","\\\\")%>/qtyCheck.do?HatsudenNo='+encodeURI(HatsudenNo);
 
i change like this... but it wont work??
0
 
leakim971PluritechnicianCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Sathish David Kumar NAuthor Commented:
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
 
leakim971PluritechnicianCommented:
>can you tell why we want to replace ??
I'm staying on .NET where the backslash are escaping the characters...

0
 
Sathish David Kumar NAuthor Commented:
If is use encodeURI() where i will decode that??
0
 
leakim971PluritechnicianCommented:
>If is use encodeURI() where i will decode that??

not needed, it's used to sent the data correctly
0
 
Sathish David Kumar NAuthor Commented:
Any update ??
0
 
ManishLeadCommented:
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
 
Sathish David Kumar NAuthor Commented:
>> 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
 
leakim971PluritechnicianCommented:
>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
 
Sathish David Kumar NAuthor Commented:
>>>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
 
leakim971PluritechnicianCommented:
What is the current charset of your page(s) ? utf-8 ?
0
 
Sathish David Kumar NAuthor Commented:
Ya UTF-8 only
0
 
leakim971PluritechnicianCommented:
0
 
Sathish David Kumar NAuthor Commented:
ya thats gd link .. but while passing from javascript to jsp thats the pblm alert msg are coming clear only ....
0
 
leakim971PluritechnicianCommented:
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
 
Sathish David Kumar NAuthor Commented:
ya without post the jsp i get that alert
0
 
leakim971PluritechnicianCommented:
Another test, do you get the alert and the encoded char with :

var url = "<%= request.getContextPath()%>/qtyCheck.do?HatsudenNo=" + encodeURI(HatsudenNo);
alert(url);
0
 
Sathish David Kumar NAuthor Commented:
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
 
leakim971PluritechnicianCommented:
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
 
Sathish David Kumar NAuthor Commented:
Its giving like this
alertURL.JPG
0
 
Sathish David Kumar NAuthor Commented:
I dont know whether its its correct encoding or not
ABCD in java class i getting like this  
0
 
leakim971PluritechnicianCommented:
>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
 
Sathish David Kumar NAuthor Commented:
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
 
leakim971PluritechnicianCommented:
You're very welcome! Thanks for the points!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 13
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now