ajax 中的响应文本 java servlet
response text java servlet in ajax
我想显示错误信息,但我不清楚得到错误信息。我只想显示消息,但在我的例子中,我显示了消息和标签 html,我已经将内容类型更改为 text/plain。我的代码:
response.setContentType("text/plain");
response.sendError(response.SC_INTERNAL_SERVER_ERROR, "user atau pass salah men!");
在ajax的错误信息中,我提醒(error.responseText);显示:
user atau pass salah men!
如何获取没有html标签的消息?谢谢
当您调用 response.sendError
时,容器会生成包含您消息的 html 页面。您需要做的是从 response.getOutputStream()
的响应中获取一个 OutputStream 并将您的消息写入其中。
您可以通过以下方式将消息写入流:
response.getOutputStream().write("user atau pass salah men!".getBytes());
我想显示错误信息,但我不清楚得到错误信息。我只想显示消息,但在我的例子中,我显示了消息和标签 html,我已经将内容类型更改为 text/plain。我的代码:
response.setContentType("text/plain");
response.sendError(response.SC_INTERNAL_SERVER_ERROR, "user atau pass salah men!");
在ajax的错误信息中,我提醒(error.responseText);显示:
user atau pass salah men!
如何获取没有html标签的消息?谢谢
当您调用 response.sendError
时,容器会生成包含您消息的 html 页面。您需要做的是从 response.getOutputStream()
的响应中获取一个 OutputStream 并将您的消息写入其中。
您可以通过以下方式将消息写入流:
response.getOutputStream().write("user atau pass salah men!".getBytes());