Wednesday, 15 February 2017

Hello World in Servlet Java.

*First You need to Download Tomcat server for execute Servlet java File.

~ Tomcat 8 Download :
 https://tomcat.apache.org/download-80.cgi

~ After Download tomcat-8.5.11.exe file you have to install them and remember port number.

*How to start tomcat server and test them.

~ First go Tomcat 8 Folder at Program file.

~ C:\Program Files\Apache Software Foundation\Tomcat 8.5\bin

~Right Click on Tomcat 8 and run as Administrator.

~ After run. open any browser and type at url :"localhost:portnumber"

~For Ex My port Number is 8088 then i have to tpye url like:"localhost:8088".

~ If you have successfully  done then Browser Page Look likes below page.





*Let's Start Hello World in Servlet java.

~ First you are beginners then you have to use Eclipse,NetBeans.

~If you are learning for Exam perpose then you should use notpad & CMD.


Hello.java


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Hello extends HttpServlet {
    
    public void doGet(HttpServletRequest rq,HttpServletResponse res) throws IOException
    {
        PrintWriter out=res.getWriter();
        
        out.println("Hello World form other World");
        
    }
 }


*Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1">
    <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>Hello</servlet-class>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>hello</servlet-name>
        <url-pattern>/hellow</url-pattern>
    </servlet-mapping>

</web-app>



Thanks ;)

Happy Coding


  












No comments:

Post a Comment