Results 1 to 6 of 6

Thread: response.sendError From Servlet

  1. #1
    Join Date
    Nov 2009
    Posts
    117

    response.sendError From Servlet

    Hello, I am searching for the details on the response.sendError from Servlet. I have read different document from internet, but they all are useless for me. I am not able to get solution for it. If anyone is having details on it, then please provide me from which I can able to understand the response.sendError from servlet. I am learning java programming currently started the Servlet and not getting this concept.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: response.sendError From Servlet

    Hello, I am also beginner in java in servlet programming. If you are making use of the sendError method in your response while calling then the container which will make use of it will consult with the different error page declarations for the web applications. If the similarity find between it and status-code syntax then the container will provide you the resource which will be provided into the location entry.

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    Re: response.sendError From Servlet

    If you want to make use of the response.sendError in your servelt the you must need to make use of the code below:
    Code:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.net.*;
    
    public class TestServlet extends HttpServlet {
      
      public void doGet(HttpServletRequest requ, HttpServletResponse resp)
                                   throws ServletException, IOException {
        resp.setBufferSize(8 * 1024); 
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();
        int total = resp.getBufferSize(); 
        log("The default buffer total is " + total);
        out.println("Wont see ");
        resp.respet();
        out.println("Doesnt seen if sendError() is called");
        if (requ.getParameter("important_parameter") == null) {
          resp.sendError(resp.SC_BAD_REQUEST, "important_parameter needed");
        }
      }
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: response.sendError From Servlet

    Hello, it is necessary to make use of the code below in your code if you want to respose.sendError from servlet. It will give you idea for using this method in your program. So, just make use of it and get solution for your problem:

    Code:
    catch (FileNotFoundException e) 
    {
    response.sendError(response.SC_NOT_FOUND);
    }
    From the code above you will able to get the knowledge about the use of the method in your program.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: response.sendError From Servlet

    Hello, you can make use of the books below for getting more knowledge about the java servlets. You can read this online also. So, make use of it.
    • Java Servlet Programming (Jason Hunter)
    • Core Servlets and JavaServer Pages
    • JavaServer Faces
    • JSP 2.0 The New Deal

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: response.sendError From Servlet

    Hey, I have got the code below which will help you to get the knowledge about to know the use of the sendError method in java.
    Code:
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class one extends HttpServlet {
    
      public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
          IOException {
        res.setBufferSize(10 * 1024); 
        res.setContentType("text/html");
        PrintWriter pw = res.getWriter();
    
        int size = res.getBufferSize(); // returns 8096 or greater
    
        log("The default buffer size is " + size);
    
        pw.println("Unable to view by client");
        res.reset();
        pw.println("Client wont see");
        res.reset();
        pw.println("if sendError() is called then this don't displayed.");
        if (req.getParameter("param") == null) {
          res.sendError(res.SC_BAD_REQUEST, "param needed");
        }
      }
    }

Similar Threads

  1. How does a servlet handles request and gives response ?
    By Lolita in forum Software Development
    Replies: 3
    Last Post: 05-02-2011, 09:28 AM
  2. JSP and Servlet problem
    By Devabrata in forum Software Development
    Replies: 5
    Last Post: 21-07-2010, 12:12 AM
  3. Servlet static variable
    By Sheenas in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 11:24 AM
  4. Difference between Servlet & ASP
    By Owen Fernandes in forum Software Development
    Replies: 5
    Last Post: 05-02-2010, 10:53 AM
  5. What is Servlet container?
    By Sonam Goenka in forum Software Development
    Replies: 5
    Last Post: 05-02-2010, 08:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,701,265.92341 seconds with 17 queries