Xml文档
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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"
version="2.4">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>helloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/qq/do</url-pattern>
</servlet-mapping>
</web-app>
<url-pattern>要注意,可以匹配地址的地方
Servlet
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class helloServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><title>helloServlet</title></head>");
out.println("<body>hello world Servlet !</body>");
out.println("</html>");
out.flush();
out.close();
}
}
本文介绍如何在web.xml中配置Servlet以及实现简单的GET请求处理。通过示例代码,展示了Servlet的基本设置及其映射规则,并提供了helloServlet类的具体实现。
421

被折叠的 条评论
为什么被折叠?



