Saturday, 17 February 2018

How to print Hello World in Servlet using xml file

How to print Hello World in Servlet using xml file,How to print Hello World in Servlet , hello world in servlet, simple program of servlet,

Let see how to print Hello world in servlet. there is three file here which we will see one by one .....

 index.jsp
this is index file which contain hyperlink and when you click on given link it show you hello world on console . 
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="dash">click here to see your output</a>
</body>
</html>

Test.java
this servlet class to print Hello worlds. before using this code 1st create a package with name com.dashzin and then write a code.
package com.dashzin;
import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Test extends HttpServlet {
   public void service(HttpServletRequest req, HttpServletResponse res)throws IOException{
               System.out.println("hello world");
   }
}

Web.xml
this xml file is use  to map your servlet class..
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Test</display-name>
 
  <welcome-file-list>
  <welcome-file>index.html</welcome-file>
  </welcome-file-list>
 
  <servlet>
  <servlet-name>Hello</servlet-name>
  <servlet-class>com.dashzin.Test</servlet-class>
  </servlet>
 
  <servlet-mapping>
  <servlet-name>Hello</servlet-name>
  <url-pattern>/dash</url-pattern>
  </servlet-mapping>
</web-app>

output 
 this all code is going to print Hello World when you will run it using server.






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