Académique Documents
Professionnel Documents
Culture Documents
public class TestServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(""); out.println(""); out.println("<h1>This is my Fisrt Servlet</h1>"); out.println(""); out.println(""); }
3. Then for compilation open your command prompt and by command prompt goes to the c:\Program files\java\jdk1.6.0\bin\javac TestServlet.java and then press enter. It creates TestServlet.class file and copy it into c:\Apache Software Foundation\tomcat 6\webapps\ROOT\WEB-INF\classes. 4. Now configure your servlet. To configure follow the steps go to the c:\Apache Software Foundation\tomcat 6\webapps\ROOT\WEB-INF and open web.xml file in edit mode write the following block of code within
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description>
<servlet> <servlet-name>Test</servlet-name> <servlet-class>TestServlet</servlet-class> </servlet> <!-- servlet mapping --> <servlet-mapping> <servlet-name>Test</servlet-name> <url-pattern>/test</url-pattern> </servlet-mapping> </web-app>
Here Test within <servlet-name>Test</servlet-name> is name of your servlet. TestServlet is your servlet class and /test is your url pattern or your servlet name by which you call this servlet on browse 5.Then Start the tomcat, go to the apache-tomcat-6.0.29\bin and double click on the startup. if a window appears like this the your tomcat have been started. To check whether you tomcat started or not open your web browser and type URL http://localhost:8080 and press enter then a windows appears like this
To run your servlet write the following URL in your browser http://localhost:8080/test and press enter then the output appears like this
BY P.sonaiyakarthick B.E.,DCSE,D.H/W.NET,