Using Genericservlet instances
Package com.kettas.servlet;Import javax.servlet.*;Import java.io.*;PublicClassGendateservletExtendsgenericservlet{@Override public void Service (servletrequest request, servletresponse response) throws Servletexce Ption, IOException {response.setcontenttype ( "text/html"); //Set response content type PrintWriter out = Response.getwriter (); //Get text written to the stream//to the client in response to the HTML text out.println ( ""<body>"); Out.println ( ""</body>"); Out.println ( "; Flush Write}}
The configuration file Web. XML is as follows:
<?xml version= "1.0" encoding= "UTF-8"?><Web-appxmlns="Http://java.sun.com/xml/ns/javaee"Xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation="Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"version="2.5" >//servlet file path<Servlet><Servlet-name>query</servlet-name> <servlet-class>com.kettas.servlet.gendateservlet</ servlet-class> </servlet>// Specifies the mapping, which indicates that entering ".../query" in the browser corresponds to the current servlet <servlet-mapping> Span class= "Hljs-tag" ><servlet-name>query</servlet-name> <url-pattern>/query</url-pattern> </ servlet-mapping></web-app>
Using Genericservlet instances