Formatter formatter = new SimpleHTMLFormatter("<b><font color='red'>", "</font></b>"); Highlighter hightlighter = new Highlighter(formatter,new QueryScorer(query) ); hightlighter.setTextFragmenter(new SimpleFragmenter(1000)); stockContent = hightlighter.getBestFragment(LuceneUtils.getInstance().getAnalyzer(), FIELD_CONTENT, stockContent);
页面显示代码
<s:property value="stockContent">
这样的结果就是页面关键字无法高亮显示,而且把font等标签也显示出来了,查看源代码,中文被转化成&数字,
<,>标签也被转换了。
要高亮显示,且查看源代码时,里面的中文不被转码掉,只要添加
escapeHtml="false"就可以了
<s:property value="stockContent" escapeHtml="false"/>