PackageCn.itcast;Importjava.io.IOException;ImportJavax.servlet.GenericServlet;Importjavax.servlet.ServletException;Importjavax.servlet.ServletRequest;ImportJavax.servlet.ServletResponse; Public classServletDemo1extendsGenericservlet {@Override Public voidService (ServletRequest req, servletresponse Res)throwsservletexception, IOException {res.getoutputstream (). Write ("Hello servlet". GetBytes ()); }}
View Code
<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "2.4"xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "><servlet> <servlet-name>ServletDemo1</servlet-name> <servlet-class>cn.itcast.servletdemo1</servlet-class></servlet><servlet-mapping> <servlet-name>ServletDemo1</servlet-name> < Url-pattern>/servletdemo1</url-pattern></servlet-mapping> <welcome-file-list> < Welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
View Code