jsp中EL表达式获取值中含逆转字符的处理
当我们在jsp页面使用EL表达式对input设置value的时候
<input type='text' value='${user.memo}'>
当${user.memo}的值中包含有单引号'的时候,就会因与外面的单引号冲突出错
这时候我们需要逆转一下,这里提供两种解决的办法:
方法1.采用<c:out></c:out>
导入相关包:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<input type='text' value='<c:out value="${user.name}" escapeXml="true"></c:out>'>
方法2.采用${fn:escapeXml(value)}
导入相关包
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<input type='text' value='${fn:escapeXml(user.memo)}'>
http://blog.xqlee.com/article/10.html