Saturday 17 February 2018

How to print Hello World in Servlet using Annotation

How to print Hello World in Servlet using Annotation ,Hello world using annotation in servlet, hello world in servlet,simple program in servlet

Annotation represents the metadata. If you use annotation, deployment descriptor (web.xml file) is not required. But you should have tomcat7 as it will not run in the previous versions of tomcat. @WebServlet annotation is used to map the servlet with the specified name.

Test.java
create a package with name com.dashzin amd then write a class with given code to print a Hello world using Annotation in annotation.


package com.dashzin;

import java.io.IOException;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/Test") // this is your class inside double quote..
public class Test extends HttpServlet {
 public void service(HttpServletRequest req,HttpServletResponse res)throws IOException{
      System.out.println("Hello world using Annotation");
 }
} 






DashZin

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 comments:

Post a Comment