采用
- ServletActionContext.getResponse().getWriter()
向前台写信息的时候,经常会出现unterminated string literal错误:未结束的字符串常量,很可能是由于字符串中存在换行符导致的。是存在\r\n
解决办法:
在将result写到前台之前,将字符串中的换行的特殊符号转义掉,
- PrintWriter pw = ServletActionContext.getResponse().getWriter();
- result = result.replace("\n\r", "<br> ");
- result = result.replace("\r\n", "<br> ");
- result = result.replace("\t", " ");
- result = result.replace(" ", " ");
- result = result.replace("\"", "\\" + "\"");
- pw.print(result);