Académique Documents
Professionnel Documents
Culture Documents
0+:
1>> In order to deploy a new servlet at new location in tomcat 6.0 server folders
create the following directories and files:
@ Files
<TOMCAT_HOME>/webapps/ROOT /MyJSP/MyServletTestJSP.jsp - Jsp file that
access the servlet file.
<TOMCAT_HOME>/webapps/ROOT /WEB-INF/classes/MyServlets/MyNewServlet.java -
It is the actual servlet file.
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
</web-app>
//==========================================================================
=======================//
By using any of your favourite editor type and save the following file with
the name "MyNewServlet.java"
//==========================================================================
========//
package MyServlets;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import java.io.IOException;
import java.io.PrintWriter;
Now compile the above java file[servlet], then after compilation the class
file for the MyNewServlet.java is created. That's the file we needs.
Deployment means introducing the created servlet into the server. Each time
a request for the Servlet[ we created ] is resolved by the server by using
mapping path in the deployment descriptor.
Type the following servlet class and mapping info into the file
<TOMCAT_HOME>/webapps/ROOT /WEB-INF/web.xml
in between the <web-app></web-app> container tags[ Just before at the </web-
app> tag]
//======================================================//
<servlet>
<servlet-name>MyNewServlet</servlet-name>
<servlet-class>MyServlets.MyNewServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyNewServlet</servlet-name>
<url-pattern>/MyServlets/MyNewServlet</url-pattern>
</servlet-mapping>
//=====================================================//
4>> Create a Jsp MyServletTestJSP.jsp file that access the servlet MyNewServlet :
//==========================================================================
====//
<%@ page contentType="text/html; charset=ISO-8859-1" session="false" %>
<%-- MyServletTestJSP.jsp --%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyServlet Test Page</title>
<head>
<body bgcolor="#ffffff" text="orange">
<form method="GET" action="http://localhost:8080/MyServlets/MyNewServlet">
<div align="center">Click here to load Servlet<input type="submit"
value="Click here" /></div>
</form>
</body>
</html>
//==========================================================================
====//
By clicking the "Click here" button, browser loads our servlet file; you
might observe this by checking the address on the Browser's location
http://localhost:8080/MyServlets/MyNewServlets
Thank you
regards
J. M. V. Swamy Naidu, M.C.A.
For more at
http://www.NaiduMCA.co.cc and
http://www.docstoc.com/profile/StudentPowerMCA