我想显示错误消息,但我不清楚收到错误消息。我只想显示消息,但在我的例子中,我显示消息和标签 html,我已经将内容类型更改为 text/plain。我的代码:
response.setContentType("text/plain");
response.sendError(response.SC_INTERNAL_SERVER_ERROR, "user atau pass salah men!");
在ajax中的错误消息中,我alert(error.responseText);显示:
用户 atau 通过 salah men!
如何获取没有html标签的消息?谢谢
最佳答案
当您调用 response.sendError
时,容器将生成包含您的消息的 html 页面。您需要做的是使用 response.getOutputStream()
从响应中获取 OutputStream 并将消息写入其中。
您可以使用以下方式将消息写入流:
response.getOutputStream().write("user atau pass salah men!".getBytes());
关于java - ajax 中的响应文本 java servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45523218/