簡體   English   中英

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); 節目:

用戶atau通過salah男子!

如何獲取沒有html標記的消息? 謝謝

當您調用response.sendError ,容器將生成包含您的消息的html頁面。 您需要做的是使用response.getOutputStream()從響應中獲取一個OutputStream並將消息寫入其中。

您可以使用以下方法將消息寫到流中:

response.getOutputStream().write("user atau pass salah men!".getBytes());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM