Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

"sendError" method as compared to "setStatus"; weired results; Help !

807605Jun 19 2007 — edited Jun 19 2007
I am using weblogic server 8.1 sp5.

I have a servlet that generates an error code and returns a "message" as a text.

The problem is that iam not getting the "message" returned on my http protocol layer.
BUT when i use "setStatus" method instead of "sendError" method, everything works fine. setStatus is deprecated and we are told not to use it.

NOTE: When i run the servlet with sendError method, it works fine on the browser BUT it is not returned in my http (at the protocol layer).

Can somebody shed some light on the difference of this behavior?


Attached is the code.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyWebServlet extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {


        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println("This is MyWebServlet");
        
        String message= "Testing custom message of a 592 Error"

        response.sendError(592,message);

        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 17 2007
Added on Jun 19 2007
12 comments
1,086 views