Professional Documents
Culture Documents
Introduction
Servlet is a web component managed by a Web container, which generates dynamic content in Web pages. A Servlet is a Java application that runs in a Web server or an application server and provides server-side processing such as accessing a database.
Servlets are protocol and platform independent server side components, written in Java, which dynamically extend Java-enabled Web Servers.
Servlet, in simple terms, is a Java program running under a Web server taking a request object as an input and responding back by a response object. A Java Servlet is an application, which runs in a Servlet container using a framework for servicing data requests.
1.
On the Desktop, Right-Click on Computer Icon as shown in figure. Now Click on the Properties tab on the pop up window.
2.
After clicking the Properties window, then the following window will be displayed.
3. Now select the Advanced System Setting tab of the window which was shown in Step:2 then following window would be displayed and select Advanced Tab of the window.
4. Now click on the Environment Variables button at the bottom of the window which is shown in Step 3 and the following window will be displayed. Then select path variable from System variables menu which is showing in flowing figure.
5. Now click on the Edit button at bottom of the window which is shown in Step 4 and the following window will be displayed. Then leave Variable name field and set Variable value: D:\Java\jdk1.7.0_03\bin then click Ok button.
6. Now, go User variables for Kalathoki menu (Kalathoki is Username) which is showing in following figure.
7. Now click New button which is showing in Step 6 and set Variable name: CLASSPATH and Variable value: .;D:\tomcat7\lib\servletapi.jar; {You should set dot semicolon(.;) before set the value of variable.} which is showing in following figure. Then click Ok button and set variable name JAVA_HOME, JRE_HOME, CATALINA_HOME and its value D:\Java\jdk1.7.0_03 , D:\Java\jre7 , D:\tomcat7 respectively.
then type cmd and press Enter from your keyboard and following window will be displayed.
Continue..
a) Type d: then press enter, b) Type cd tomcat7\bin then press enter. Example: Showing in following figure.
c) Then type startup.bat or only startup then press enter. And following window will be displayed showing the INFO: server startup in ms.
Continue..
Open your browser and type on search bar http://localhost:8080 and press enter then you will see following window. If following window displayed then your tomcat configuration is successfully completed.
HelloWord.java
public class HelloWord 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("<title>Hello Word!</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Hello Word!</h1>"); out.println("</body>"); out.println("</html>"); } }
Web.xml
<web-app> <servlet> <servlet-name>test</servlet-name> <servlet-class>HelloWord</servlet-class> </servlet> <servlet-mapping> <servlet-name>test</servlet-name> <url-pattern>/helloword</url-pattern> </servlet-mapping> </web-app>
OutPut
Type URL on the browsers search bar http://localhost:8080/kalathoki/helloword and press enter then you will get output as: following figure:
Port No
Protocol
Server
Project Name
URL
Request
Client
URL
Request
Client
Tomcat uses the mapping info in a configuration file called web.xml of the web application to find the right servlet
Request
Client
Tomcat uses the mapping info in a configuration file called web.xml of the web application to find the right servlet
Client
Client
Client
Thank You !