1 package com.jsn.web.servlet; 2 3 import java.io.IOException; 4 5 import javax.servlet.Servlet; 6 import javax.servlet.ServletConfig; 7 import javax.servlet.ServletException; 8 import javax.servlet.ServletRequest; 9 import javax.servlet.ServletResponse; 10 11 public class HelloServlet implements Servlet { 12 13 @Override 14 public void destroy() { 15 // TODO Auto-generated method stub 16 System.out.println("hello"); 17 } 18 19 @Override 20 public ServletConfig getServletConfig() { 21 // TODO Auto-generated method stub 22 return null; 23 } 24 25 @Override 26 public String getServletInfo() { 27 // TODO Auto-generated method stub 28 return null; 29 } 30 31 @Override 32 public void init(ServletConfig arg0) throws ServletException { 33 // TODO Auto-generated method stub 34 System.out.println("hello init"); 35 } 36 37 @Override 38 public void service(ServletRequest arg0, ServletResponse response) throws ServletException, IOException { 39 // TODO Auto-generated method stub 40 response.getWriter().write("hello service response"); 41 } 42 43 }
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> 3 <display-name>dyweb</display-name> 4 5 <servlet> 6 <servlet-name>HelloServlet</servlet-name> 7 <servlet-class>com.jsn.web.servlet.HelloServlet</servlet-class> 8 9 10 11 </servlet> 12 <servlet-mapping> 13 <servlet-name>HelloServlet</servlet-name> 14 <url-pattern>/hellworld</url-pattern> 15 16 </servlet-mapping> 17 <welcome-file-list> 18 <welcome-file>index.html</welcome-file> 19 <welcome-file>index.htm</welcome-file> 20 <welcome-file>index.jsp</welcome-file> 21 <welcome-file>default.html</welcome-file> 22 <welcome-file>default.htm</welcome-file> 23 <welcome-file>default.jsp</welcome-file> 24 </welcome-file-list> 25 </web-app>