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 6245347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:29:18+00:00 2026-05-24T12:29:18+00:00

I have a web application in Java which does data exchange using XML. I

  • 0

I have a web application in Java which does data exchange using XML. I have written a servlet and it uses HTTP Post to upload the XML file from a particular client. Once the Post method is completed successfully, it sends 200 OK message to the client (using the default web server HTTP status). Now I need to include some HTTP status code in my application so that the client gets some HTTP status message (eg. 400 Bad request, 502 bad gateway) when there is an issue with the upload. How should I add the HTTP status codes in my web application? Please help me with suggestion.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-24T12:29:18+00:00Added an answer on May 24, 2026 at 12:29 pm

    You can use HttpServletResponse#setStatus() or HttpServletResponse#sendError().

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
    
        // handle upload
    
        // if error
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    
        // or
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                           "An unknown error occurred");
    }
    

    The methods differ in what they cause the servlet container to do, so choose the one most appropriate for your situation.

    • setStatus()

      If this method is used to set an error code, then the container’s
      error page mechanism will not be triggered.

    • sendError()

      Sends an error response to the client using the specified status and
      clears the buffer. The server defaults to creating the response to
      look like an HTML-formatted server error page containing the specified
      message

    The list of status code constants is available in the Field Summary of the javadoc. For the codes in your question:

    • HttpServletResponse.SC_BAD_REQUEST
    • HttpServletResponse.SC_BAD_GATEWAY
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application (Java, Websphere, JSP) which allows co-workers to register visitors
We have a java web service application that uses log4j to do logging. An
I have a java application that has Web Services published using Axis. With the
Here's the scenario: I have a multi threaded java web application which is running
I have an application solution which is made up of a web app written
I have a server behind a firewall. It runs a web application (Java servlets
In a Java web application I have a recurring message load of type A
I have a web application written in C# that consumes several internal web services.
I have an application which uses JSPs and Servlets and deployed on IBM-WASCE 2.1.
Application configuration: Web application using java first method of creating JAX-WS 2.0 Web Services

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.