Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



response.sendError From Servlet

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 11-02-2010
Member
 
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.

Reply With Quote
  #2  
Old 11-02-2010
Member
 
Join Date: May 2008
Posts: 2,004
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.
Reply With Quote
  #3  
Old 11-02-2010
Member
 
Join Date: Apr 2008
Posts: 1,946
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");
    }
  }
}
Reply With Quote
  #4  
Old 11-02-2010
Member
 
Join Date: May 2008
Posts: 2,286
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.
Reply With Quote
  #5  
Old 11-02-2010
Member
 
Join Date: Oct 2005
Posts: 2,386
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
Reply With Quote
  #6  
Old 11-02-2010
Member
 
Join Date: Apr 2008
Posts: 1,997
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");
    }
  }
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "response.sendError From Servlet"
Thread Thread Starter Forum Replies Last Post
How does a servlet handles request and gives response ? Lolita Software Development 3 05-02-2011 08:28 AM
JSP and Servlet problem Devabrata Software Development 5 21-07-2010 12:12 AM
Servlet static variable Sheenas Software Development 5 06-03-2010 10:24 AM
Difference between Servlet & ASP Owen Fernandes Software Development 5 05-02-2010 09:53 AM
What is Servlet container? Sonam Goenka Software Development 5 05-02-2010 07:13 AM


All times are GMT +5.5. The time now is 02:50 PM.