-1

I am sending the the value from my jsp to my servlet in url parsing.

The value contains the special character (), but when I am receiving the value it is &#40 and &#41.

How to decode this back to ()?

jsp code

var devicename=document.getElementById('s_loc_1').value;    
    var param=devicename;
    param=encodeURIComponent(devicename);
    var updatedevsaturl="http://"+window.location.host+"/services/PCEquipmentDevice?productid={}&action=updatePCDeviceStatus&reqby={}&param="+param;
    var productId=document.getElementById('pid').value;
    updatedevsaturl=sustituteParameter(updatedevsaturl,productId);
    updatedevsaturl=sustituteParameter(updatedevsaturl,userUpi);
    alert(updatedevsaturl);
    $.ajax({
        type : "GET",
        timeout:20000,
        url : updatedevsaturl,
        async: false,
        dataType : "xml",
        success: function(data) {   }, error: function (xhr, ajaxOptions, thrownError) {
            alert('Service Unavailable - VPU List');
        }
    });

java code to decode

if(action.equals("updatePCDeviceStatus")){
        System.out.println("param: "+param);
        //String decodeparam3 = new String(param.getBytes("UTF-8"),"ASCII");
        //String decodeparam3 =URLDecoder.decode(param, "UTF-8");
        String decodeparam3= URLDecoder.decode(param, "ISO-8859-1");    
        System.out.println("decodeparam132 "+ decodeparam3);

I tried all the ways give on net but didnt workenter code here

input at jsp 2-in-1 Laptop (12.5 inches) output at servlet 2-in-1 Laptop &#4012.5 inches&#41

  • for example my input is 2-in-1 Laptop (12.5 inches) and i getting on servlet is 2-in-1 Laptop (12.5 inches) – Apoorv Jain Feb 20 '17 at 07:54
  • You haven't provided enough context to help you out. Please post a [mcve]. – shmosel Feb 20 '17 at 07:56
  • This is not URL encoding. These are HTML escape sequences, and you should *not* be sending them like that from your JSP. Please post the form in the JSP that causes these characters to be sent. – RealSkeptic Feb 20 '17 at 07:59
  • See http://stackoverflow.com/a/24575417/1098603 – Matthieu Feb 20 '17 at 08:00
  • In my jsp I am using the encodeURIComponent to encoded parameter and then I am send that parameter to a servlet by url parsing but when i am try to decode the same parameter it is not able to decode the special characters for example parameter- 2-in-1 Laptop (12.5 inches) with encoding after decoding at servlet 2-in-1 Laptop (12.5 inches) – Apoorv Jain Feb 20 '17 at 08:00
  • 1
    (1) Don't *describe* your code, *post* your code. (2) To add information, [edit] the question and add the information. – RealSkeptic Feb 20 '17 at 08:02

1 Answers1

0

This is ASCII code for "(". Look at this answer Java: How to unescape HTML character entities in Java? . You have to create a char from that html entity.

Community
  • 1
  • 1
Stimpson Cat
  • 1,444
  • 19
  • 44