|
| ||||||||||
| Tags: java, programming, response senderror, servelet |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| response.sendError From Servlet
|
|
#2
| |||
| |||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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);
} |
|
#5
| ||||
| ||||
| 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.
|
|
#6
| ||||
| ||||
| 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");
}
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |