Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

Tuesday, December 11, 2007

java code for Exceptions in Servlet

/*

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

DeliberateException
DeliberateException


DeliberateException
/deliberateException


*/

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DeliberateException extends HttpServlet {
public void init(ServletConfig config) throws ServletException {
super.init(config);
throw new NullPointerException();
}

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
ServletOutputStream out = res.getOutputStream();
res.setContentType("text/html");
out.println("Exception Thrower");
out.println("You'll never see this!");

}
}

No comments: