Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: forced HTTP 500 error

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default forced HTTP 500 error

    Hi all,

    I would like to ask for some help.

    I made a java servlet. It receives information from sender through http get/post and it processes the information (for example it store received data to database).

    My problem is how can I throw back an http 500 exception to the sender if there is an error during data processing?

    My code:
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
        {
            ...
            PrintWriter out = response.getWriter();
            try
            {
                ...
     
                Integer[] i = new Integer[1];
     
                // it will throw an exception
                i[5] = Integer.valueOf(5);
     
                // out.println("ok");
            }
            catch (Exception ex)
            {
               // TODO to write: send back HTTP 500 error
     
                throw new ServletException(ex);
            }
            finally 
            { 
                out.close();
            }
        }

    Thank you, alma


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    184
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: forced HTTP 500 error

    Why would you want to send that sort of header under these circumstances? It might be better to send a more informative response that notifies the user - perhaps one that might not drive a user away. That being said, you can modify the header information using the HttpServletResponse object setHeader method.

Similar Threads

  1. How Manipulate HTTP response?
    By nikos in forum Java Networking
    Replies: 1
    Last Post: October 7th, 2010, 01:22 PM
  2. Sending XML over HTTP to Another Application
    By darasgar in forum Java Servlet
    Replies: 2
    Last Post: July 14th, 2010, 02:56 PM
  3. HTTP Status 500 -
    By mqt in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 6th, 2010, 02:09 AM
  4. Replies: 1
    Last Post: March 31st, 2010, 10:42 PM
  5. cant get rid of http connection
    By kartik in forum Java Networking
    Replies: 1
    Last Post: July 21st, 2009, 04:09 AM

Tags for this Thread