简体   繁体   中英

response text java servlet in ajax

I want to display error message but I not clear get the error message. I just want display just the message, but in my case I show the message and the tag html, I already change the content type to text/plain. my code:

response.setContentType("text/plain");
            response.sendError(response.SC_INTERNAL_SERVER_ERROR, "user atau pass salah men!");

in error message in ajax, I alert(error.responseText); show:

user atau pass salah men!

how to get the message without the html tag? thanks

When you call response.sendError the container is generating an html page with your message. What you need to do instead is get an OutputStream from the response with response.getOutputStream() and write your message to it.

You can write your message to the stream with:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM