jsp中的字符常量无效

时间:2014-05-06 03:03:53

标签: java jsp

我的webapp会抛出此错误:

weblogic.servlet.jsp.CompilationException: Failed to compile JSP /pages/workbench/user/taskassessmentexample.jsp
taskassessmentexample.jsp:204:230: Invalid character constant
                                                    String message = "<b>" + riskNote.getUser() + "</b> (<span style=\"font-size:80%\">" + riskNote.getDisplayTimeStamp() + "</span> ) :&nbsp; <span style=\"font-style:italic;\">" + riskNote.getMessage().replaceAll(&apos;\n&apos;,&apos;<br/>&apos;) + "</span><br/>";
                                                                                                                                                                                                                                                               ^----^

    at weblogic.servlet.jsp.JavelinxJSPStub.reportCompilationErrorIfNeccessary(JavelinxJSPStub.java:226)

生成它的JSP是:

String message = "<b>" + riskNote.getUser() + "</b> (<span style=\"font-size:80%\">" + riskNote.getDisplayTimeStamp() + "</span> ) :&nbsp; <span style=\"font-style:italic;\">" + riskNote.getMessage().replaceAll('\n','<br/>') + "</span><br/>";
out.println(message);

我错过了一些非常明显的东西吗?

1 个答案:

答案 0 :(得分:6)

您应该在以下位置看到编译错误:

... replaceAll('\n','<br/>') ...

因为这些参数应该是用双引号括起来的字符串:

... replaceAll("\n", "<br/>") ...