There are two problems here.
First, \ is an escape character in JS strings. If you want to represent \ in the JS line, you need to get away from it twice: \\ . The easiest way is to use JSTL fn:replace for this.
var jsVariable = "${fn:replace(javaVariable, '\\', '\\\\')}";
Secondly, you want to send it as a URL parameter. \ is an illegal character in the URL parameter. You need to URL encode it. The easiest way is to use the Javascript escape() function to do this.
var urlParameter = escape(jsVariable);
Summarizing,
oScript.text+= "'script':'<%= request.getContextPath() %>/uploadFile?portletId=${portletId}&remoteFolder=${remoteFolder}',";
must be replaced by
oScript.text += "'script':" + "'${pageContext.request.contextPath}/uploadFile" + "?portletId=${portletId}" + "&remoteFolder=" + escape("${fn:replace(remoteFolder, '\\', '\\\\')}") + "',";
Alternatively, you can use / instead of \ as a file path separator. This works fine on Windows as well. You do not need to avoid them for use in strings, however you still need to URL-encode it.
oScript.text += "'script':" + "'${pageContext.request.contextPath}/uploadFile" + "?portletId=${portletId}" + "&remoteFolder=" + escape("${remoteFolder}") + "',";
source share