skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Showing posts with label JSTL Example. Show all posts
Showing posts with label JSTL Example. Show all posts
Saturday, October 13, 2012

Custom EL Function to escape JS Special Characters

Posted by Raju Gupta at 7:00 AM – 0 comments
 

A custom EL function to escape javascript special characters present in a JSTL variable.

There may be situations in which we need to pass JSTL String Variable to Javascript functions. If there are javascript special characters such as single-quote, double-quote etc., present in the JSTL variable value, it would result in script error. It is always advisable to escape such special characters before passing to javascript function. This code-snippet focusses on writing a custom EL function to address this issue.


//This class requires Apache commons-lang JAR
//Tag Handler Class for custom EL Function

package util;   
  
import org.apache.commons.lang.StringEscapeUtils;   
  
public class JSEscUtil {   
  
    public static String escapeJSString(final String s) {   
        return StringEscapeUtils.escapeJavaScript(s);   
    }   
} 


[ Read More ]
Read more...
Older Posts
Subscribe to: Posts ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger