Note that there are some explanatory texts on larger screens.

plurals
  1. POPlain text 400 error message in struts2 + Tomcat
    primarykey
    data
    text
    <p>I want an action to issue a 400 error HTTP response with an explanation of the problem in text/plain whenever a validation fails.</p> <p>I can use org.apache.struts2.dispatcher.HttpHeaderResult to get the 400 error:</p> <pre><code>@Action(results = { @Result(name = SUCCESS, type=ResultTypes.HTTP_HEADER, params = { "status", "200" }), @Result(name = INPUT, type=ResultTypes.HTTP_HEADER, params = { "error", "400", "errorMessage", "${errorMessage}" }) }) @Override public String execute() { return INPUT; } public String getErrorMessage() { return "There was an error"; } </code></pre> <p>The problem is that Tomcat "wraps" my response into an HTML page as follows:</p> <pre><code>HTTP/1.1 400 Bad Request Server: Apache-Coyote/1.1 Content-Type: text/html;charset=utf-8 Content-Length: 1214 Date: Sun, 20 Mar 2011 00:43:55 GMT Connection: close &lt;html&gt;&lt;head&gt;&lt;title&gt;Apache Tomcat/6.0.29 - Error report&lt;/title&gt;&lt;style&gt;&lt;!-- H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} A {color : black;} A.name {color : black;} HR {color : #525D76;}--&gt;&lt;/style&gt; &lt;/head&gt; &lt;body&gt;&lt;h1&gt;HTTP Status 400 - There was an error&lt;/h1&gt;&lt;HR size="1" noshade="noshade"&gt; &lt;p&gt;&lt;b&gt;type&lt;/b&gt; Status report&lt;/p&gt;&lt;p&gt;&lt;b&gt;message&lt;/b&gt; &lt;u&gt;There was an error&lt;/u&gt;&lt;/p&gt; &lt;p&gt;&lt;b&gt;description&lt;/b&gt; &lt;u&gt;The request sent by the client was syntactically incorrect (There was an error).&lt;/u&gt;&lt;/p&gt; &lt;HR size="1" noshade="noshade"&gt;&lt;h3&gt;Apache Tomcat/6.0.29&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt; </code></pre> <p>While I would simply want something like:</p> <pre><code>HTTP/1.1 400 Bad Request Server: Apache-Coyote/1.1 Content-Type: text/plain;charset=utf-8 Content-Length: 18 Date: Sun, 20 Mar 2011 00:43:55 GMT Connection: close There was an error </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload