Decode in Java webscript

cancel
Showing results for 
Search instead for 
Did you mean: 
ratik_singhal
Established Member

Decode in Java webscript

Hello All,

I am calling a java webscript from a ftl. 

var uri = Alfresco.constants.PROXY_URI+"/vs/insurancetype?" + encodeURIComponent("company="+companyValue+"&insurancetype="+insuranceValue);
this.register = function () {
Alfresco.util.Ajax.jsonGet({
       url: uri,
       successCallback: {
                fn: this.updateSubInsuranceType,
                scope: this
      },
      failureCallback: {
                fn: function(){},
                scope: this
     }
});

Passing Parameter:

var companyValue = "A&B Company";

var insuranceValue = "R&K insurance"

Request URL:

  1. Request URL:

When I get the request in Java Webscript. 

final String insuranceCompany = req.getParameter("company");   ///companyValueA
final String insurancetype = req.getParameter("insurancetype");   /// insuranceValue=R

Basically, I am not getting right parameter from the request object. 
Please suggest...

2 Replies
afaust
Master

Re: Decode in Java webscript

You should not be encoding the entire URL arguments via encodeURIComponent. It is more appropriate to encode only the values individually before combining them into the URL. So the URL should look more like

http://localhost:8080/share/proxy/alfresco/vs/insurance-sub-type?company=Company%201&insurancetype=D...

(Note: You also do not need the leading slash in your URL addition since the PROXY_URI already ends with a slash)

ratik_singhal
Established Member

Re: Decode in Java webscript

Hello Thanks for reply.

I have already tried this way too...Only encode value "A&B Company" but still in WebScriptRequest I am getting full path and parameters value without encoding. I have tried to decode as well in java webscript as well.