Search code examples
jspglassfishresponseplaintext

Plain text JSP response


I'm stuck on this problem. The answer might be straight forward, but for the life of me, I can't figure it out.

Here is my very simple jsp file:

<%@page contentType="text/plain" 
import="java.util.*" 
import="subscriberapi.SubscriberAPI"
pageEncoding="UTF-8"%>
<%!private String Check(String jsonText)
{
    SubscriberAPI subscriberAPI = new SubscriberAPI();
    return subscriberAPI.Check(jsonText);
}%>
<%response.setContentType("text/plain");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("pragma","no-cache");%>
<%=Check(request.getParameter("jsonText"))%>

I would like the output to be:

{"Status":true,"Message":"All good"}

But the output I get is:

<html>
<head></head>
<body>
<pre style="word-wrap: break-word; white-space: pre-wrap;">{"Status":true,"Message":"All good"}</pre>
</body>
</html>

It looks correct in a browser but the actual response goes to another process, that doesn't want the html.

How do I get rid of the html build around the response? Is this set by Glassfish?


Solution

  • :blush: Epic fail!

    When Google Chrome is presented with text/plain it will wrap it in html (as above). I feel like such a noob developer. I should have checked it on other browsers and or wrote a test app. In any case, I followed BalusC advice and made a Servlet