Saturday 22 February 2014

Internal Server Error



Internal server Error


The server encountered an internal error (Internal Server Error) that prevented 

it from fulfilling this request.







Problem Description:

Invalid class file format.

Such error occurred when executing servlet program.

Solution :

Check whether you are installed java on your machine.

If it is installed then please check jre file of java is corrupted or no.

Such problem only occur when Jre on your machine was corrupted.

Just uninstall java and install fresh copy of Java.

Again execute your program and see output will appear.

Thank you.
 

Friday 10 January 2014

HOW TO COMPILE AND RUN SERVLET PROGRAM


    1)      SAVE SERVLET PROGRAM IN BELOW DIRECTORY OF YOUR MACHINE
C:\Program Files\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes
    
    2)      SET ENVIRONMENT VARIABLE

JUST GO TO MY COMPUTER
RIGHT CLICK ON IT .
GO TO PROPERTIES

        3)      GO TO ADVANCED TAB
CLICK ON ENVIRONMENT VARIABLE TAB




         4)      SET THE FOLLOWING PATH

i)        CLASSPATH
                  Variable name: CLASSPATH
                  Variable value: C:\Program Files\Apache Tomcat 4.0\common\lib\servlet.jar; C:\Program Files\Java\jdk1.5.0_06;

                   PATH ABRIVIATION
                   CLASSPATH
                   Path up to Apache tomcat\common\lib\servlet.jar file,then semicolon followed by jdk directory.

ii)      PATH
                  Variable name: PATH
                  Variable value: C:\Program Files\Java\jdk1.5.0_06\bin;

                  PATH ABRIVIATION
                   PATH
                    Path up to jdk\bin directory .

       5)      AFTER THAT COPY servlet.jar FILE FROM

          C:\Program Files\Apache Tomcat 4.0\common\lib
          AND PASTE IN FOLLOWING DIRECTORY
          C:\Program Files\Java\jre1.5.0_06\lib\ext
          OPEN COMMAND PROMPT & COMPILE SOURCE PROGRAM


          6)      Start tomcat server,

          7)      Go to Internet Explorer, Type following URL

         http://localhost:8080/examples/servlet/Nameof yourServlet


          8)      Thank you

Hello World Program of Servlet

What is Servlet?                                                                                                     
Java Servlet is programs that run on a Web or Application server and act as a middle layer between a requests coming from a Web browser or other HTTP client and databases or applications on the HTTP server.

Types of Servlet

Generic Servlet

The Generic Servlet is an abstract class that is extended by HttpServlet to provide HTTP protocol-specific methods.
The Generic Servlet does not include protocol-specific methods for handling request parameters, cookies, sessions and setting response headers.
Generic Servlet is not specific to any protocol.

       HTTP Servlet

An abstract class that simplifies writing HTTP servlet. It extends the GenericServlet base class and provides an framework for handling the HTTP protocol.
The HttpServlet subclass passes generic service method requests to the relevant doGet () or doPost () method.
HttpServlet only supports HTTP and HTTPS protocol.


HelloWorld Program

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorldExample extends HttpServlet {
 public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
    {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>HelloWorld</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

Servlet Packages

            Servlet can be created using the  javax.servlet  and  javax.servlet.http  packages, which are a standard part of the Java's enterprise edition, an expanded version of the Java class library that supports large-scale development projects.

HelloWorld Program of Servlet

1. import package
import java.io.*;
This package is for input /output operation.

import javax.servlet.*;
import javax.servlet.http.*;
                       


This two package mainly responsible for Servlets implementation.     

Servlet life cycle            
                                                                                    
                    A servlet life cycle can be defined as the entire process from its creation till the destruction. The following are the paths followed by a servlet.              
The servlet is initialized by calling the init () method.                                                         
The servlet calls service() method to process a client's request.                                     The servlet is terminated by calling the destroy() method.                                           Finally, servlet is garbage collected by the garbage collector of the JVM.                                                                                                                                                                                                                                                                                                                                                            
What is the difference between difference between doGet() and doPost()?    
                                                                                                                                                                   
          doGet () and doPost() are HTTP requests handled by servlet classes.                 
                             In doGet (), the parameters are appended to the URL and sent along with header information. This does not happen in case of doPost(). In doPost(), the parameters are sent separately.                                                                                                                                                                                                                                                                             Since most of the web servers support only a limited amount of information to be attached to the headers, the size of this header should not exceed 1024 bytes. doPost() does not have this constraint.                                                                                                                                                                                                                                                Usually programmers find it difficult to choose between doGet() and doPost().                                                                                                                                                                       doGet() shall be used when small amount of data and insensitive data like a query has to be sent as a request.                                                                                                                                                                                                                                                                         doPost() shall be used when comparatively large amount of sensitive data has to be sent. Examples are sending data after filling up a form or sending login id and password.                                                                                                                      

ShareThis

Related Posts Plugin for WordPress, Blogger...