java生成jsp静态页面时#造成错误
时间: 2016-10-31来源:开源中国
前景提要
HDC调试需求开发(15万预算),能者速来!>>>
我用java替换jsp模板占位符,并生成JSP具体页面时,发现一个问题,只要是要生成的内容中包含#{}的内容,替换后,再访问这个页面就会报错。
数据库中的要替换jsp占位符的 content 内容如下:
#{sdfsd}
代码如下,功能是将content的内容替换jsp页面中的'###content###'占位符:
String content = htmlToText(blog.getBlogContent()); templateContent = templateContent.replaceAll("###content###",content);

htmlToText方法代码如下:
/** * 转义#和$ * @param str 要转义的内容 add by www.blog-china.cn * @return */ privateString htmlToText(String str) { String [] regExStrs = {"#","\$"}; str = str.replaceAll(regExStrs[0],"\\\\#"); str = str.replaceAll(regExStrs[1],"\\\$"); returnstr; }





项目代码生成的过程中不报错,但是当访问这个生成的Jsp页面时,就会报如下的错误:
org.apache.jasper.JasperException: /WEB-INF/blog_file/guopengfei/1/1477405966557.jsp (line:14, column:9) #{...} is not allowed in template text at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42) at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)








急求大神如何解决将包含#{}的内容转义?注意,要替换的内容中不管包含任何内容,都不应该被解析,比如即使要替换的内容包含#{userName}、或者${userName }等类似的el表达式字符串,生成的jsp页面也不应该在解析成一个el表达式,而是鸳鸯输出 #{userName}、或者${userName } 字符。

科技资讯:

科技学院:

科技百科:

科技书籍:

网站大全:

软件大全:

热门排行