Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7640101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:35:25+00:00 2026-05-31T08:35:25+00:00

I’m working on an AJAX-enabled JavaScript frontend that makes calls to a Java backend

  • 0

I’m working on an AJAX-enabled JavaScript frontend that makes calls to a Java backend written with Struts. My problem is that when the backend throws an exception, the client still sees a “200 OK” HTTP response code instead of “500 Internal Server Error” like one would expect.

This is tripping me up repeatedly because my 3rd-party client JavaScript library depends on HTTP status codes to determine if something is wrong with an AJAX call, as most modern libraries normally do. The errors pass undetected until my code blows up when it tries to parse what would normally be JSON.

I really want to avoid hacking my client JS library in order to gracefully handle these errors. So then, how can I make Struts give me a 500 status code when there’s been an unhandled exception in the backend? Shouldn’t this be Struts’s default behavior?

Edit: The client-side code is irrelevant in this case. I am needing to fix the server so it sends the appropriate status code when unhandled exceptions happen. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:35:26+00:00Added an answer on May 31, 2026 at 8:35 am

    I figured out one way to do it. I’m not sure if it’s the best or easiest, but it works. I found the Struts Exception Configuration guide and added the following to my <package> inside struts.xml:

    <global-results>
      <result name="exception">/exception.jsp</result>
    </global-results>
    
    <global-exception-mappings>
      <exception-mapping exception="java.lang.Exception" result="exception" />
    </global-exception-mappings>
    

    This causes all unhandled exceptions to be redirected to /exception.jsp. And here are the JSP’s contents:

    <%@ taglib prefix="s" uri="/struts-tags" %>
    <%@ page contentType="application/json; charset=UTF-8" %>
    <% response.setStatus(500); %>
    {"success": false,"errors": "<s:property value="%{exception.message}"/>"}
    

    You’ll note on the 3rd line that I manually set the response code to 500.

    This gave me a new problem: exceptions were not being logged any more. As suggested in the aforementioned Struts guide, I solved this by adding the following to my <package> in struts.xml as well:

    <interceptors>
        <interceptor-stack name="appDefaultStack">
            <interceptor-ref name="defaultStack">
                <param name="exception.logEnabled">true</param>
                 <param name="exception.logLevel">ERROR</param>
            </interceptor-ref>
        </interceptor-stack>
    </interceptors>
    
    <default-interceptor-ref name="appDefaultStack" />
    

    Struts: -1 for making such a simple and obvious feature NOT the default, and another -1 for making the solution so obtuse.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.