...::: Recent Updates :::...

Monday, June 18, 2012

generate page not found error

Download Code
<!--Write a servlet that returns a “page not found” error page (404) unless the user supplies a favouriteLanguage request (form) parameter with a value of “Java.” -->

<!-- Check.java -->
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Check extends HttpServlet
{
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
    {
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();
        String language=request.getParameter("language");
        language=language.toLowerCase();
        if(language.equals("java"))   
        {
            out.println("<html><head><title>Error Page :)</title></head><body>");
            out.println("<h1>Welcome dude nice Choice</h1></body></html>");
        }
        else
        {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);       
        }
        out.close();
    }
}

<!-- favlanguage.html -->
<html>
<head>
    <title>Favourate Language</title>
</head>
    <body>
        <form name=f1 method="get" action="/NotFoundError/error_page">
            Enter Your favourate Language:-<input type="text" name="language" /><br>
            <input type="submit" name="submit" value="Submit" />
        </form>
    </body>
</html>

No comments:

Post a Comment