title: How to escape JavaScript in JSP?
body: <p>I'm totally stuck on this, I'm trying to escape a single quote in a JSP. I have some data that I'm outputting directly into a JS string and the single quotes seem to be causing issues.</p>
  
  <p>Here is my code:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dsp:droplet name="/atg/dynamo/droplet/ForEach"&gt;
    &lt;dsp:param value="${CommerceItems}" name="array" /&gt;
    &lt;dsp:param name="elementName" value="CommerceItem" /&gt;
    &lt;dsp:oparam name="outputStart"&gt;
      var itemNameList ='
    &lt;/dsp:oparam&gt;
    &lt;dsp:oparam name="output"&gt;
      &lt;dsp:getvalueof id="Desc" param="CommerceItem.auxiliaryData.productRef.displayName"&gt;
        ${fn:replace(Desc, "'", "\\/'")}
      &lt;/dsp:getvalueof&gt;
    &lt;/dsp:oparam&gt;
    &lt;dsp:oparam name="outputEnd"&gt;';&lt;/dsp:oparam&gt;
  &lt;/dsp:droplet&gt;
  </code></pre>
  
  <p>And here is the output that Im getting:</p>
  
  <pre class="lang-js prettyprint-override"><code>var itemNameList ='
  Weyland Estate Santa Barbara Pinot Noir
  Raymond \/'Prodigal\/' North Coast Cabernet Sauvignon
  Chateau Haute Tuque'; 
  </code></pre>
  
  <p>But this is wrong, and I just need <code>/'Prodigal'/</code> or no single quotes at all!</p>
  
  <hr>
  
  <p><strong>EDIT</strong>: Or I actually need to escape quotes with <code>\</code> backward slash?</p>