[Java] 纯文本查看 复制代码
public class ServletDemo1 implements Servlet{
@Override
/**
* 为用户处理请求和响应的方法.
*/
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
res.getWriter().println("Hello Servlet...");
}
...
}
[XML] 纯文本查看 复制代码
<!-- 配置Servlet -->
<servlet>
<!-- Servlet的名称 -->
<servlet-name>test1</servlet-name>
<!-- SErvlet的全路径 -->
<servlet-class>com.itheima.a_servlet.ServletDemo1</servlet-class>
</servlet>
<!-- Servlet的映射 -->
<servlet-mapping>
<!-- Servlet的名称 -->
<servlet-name>test1</servlet-name>
<!-- Servlet的访问路径 -->
<url-pattern>/ServletDemo1</url-pattern>
</servlet-mapping>
[XML] 纯文本查看 复制代码
<servlet>
<servlet-name>ServletDemo4</servlet-name>
<servlet-class>com.itheima.a_servlet.ServletDemo4</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletDemo4</servlet-name>
<url-pattern>/ServletDemo4</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ServletDemo5</servlet-name>
<servlet-class>com.itheima.a_servlet.ServletDemo5</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletDemo5</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ServletDemo6</servlet-name>
<servlet-class>com.itheima.a_servlet.ServletDemo6</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletDemo6</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>