Servlet课程0424(三) 通过继承HttpServlet来开发Servlet
//这是第三种开发servlet的方法,通过继承httpservlet
package com.tsinghua; import javax.servlet.http.*;
import java.io.*; public class HelloHttp extends HttpServlet{ //处理get请求
//req用于获得客户端(浏览器)的信息
//res用于向 客户端(浏览器)返回信息
public void doGet(HttpServletRequest req, HttpServletResponse res)
{
//业务逻辑
try{
PrintWriter pw = res.getWriter();
pw.println("Hello,http!"); }
catch(Exception ex)
{
ex.printStackTrace();
} } //处理get请求
//req用于获得客户端(浏览器)的信息
//res用于向 客户端(浏览器)返回信息
public void doPost(HttpServletRequest req, HttpServletResponse res)
{ this.doGet(req,res); } }
web.xml Servlet配置文件
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--> <web-app xmlns="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"> <display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description> <!-- JSPC servlet mapping start -->
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.tsinghua.Hello</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/sp</url-pattern>
</servlet-mapping> <servlet>
<servlet-name>hellogen</servlet-name>
<servlet-class>com.tsinghua.HelloGen</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>hellogen</servlet-name>
<url-pattern>/hellogen</url-pattern>
</servlet-mapping> <servlet>
<servlet-name>hellohttp</servlet-name>
<servlet-class>com.tsinghua.HelloHttp</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>hellohttp</servlet-name>
<url-pattern>/hellohttp</url-pattern>
</servlet-mapping>
<!-- JSPC servlet mapping end -->
</web-app>
Servlet课程0424(三) 通过继承HttpServlet来开发Servlet的更多相关文章
- java一个类 继承HttpServlet 和实现Servlet区别
java一个类 继承HttpServlet 和实现Servlet区别 servlet 是一个接口,如果实现这个接口,那么就必须实现接口里面定义的所有方法 而HttpServlet实现了servlet接 ...
- Servlet-通过继承HttpServlet类实现Servlet程序
通过继承HttpServlet类实现Servlet程序(开发一般用) 一般在实际项目开发中,都是使用继承 HttpServlet类的方式实现Servlet程序 1,编写一个类去继承 HttpServl ...
- Servlet课程0424(二) 通过继承GenericServlet来开发Servlet
//这是第二种开发servlet的方法(继承GernericServlet) package com.tsinghua; import javax.servlet.GenericServlet; im ...
- JavaWeb学习之Servlet(二)----Servlet的生命周期、继承结构、修改Servlet模板
[声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4140466.html 一.http协议回顾: 在上一篇文章中:JavaW ...
- (转)JavaWeb学习之Servlet(二)----Servlet的生命周期、继承结构、修改Servlet模板
[声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4140466.html 一.http协议回顾: 在上一篇文章中:JavaW ...
- Servlet课程0424(一) 通过实现Servlet接口来开发Servlet
//这是我的第一个Servlet,使用实现Servlet接口的方式来开发 package com.tsinghua; import javax.servlet.*; import java.io.*; ...
- servlet实现的三种方式对比(servlet 和GenericServlet和HttpServlet)
第一种: 实现Servlet 接口 第二种: 继承GenericServlet 第三种 继承HttpServlet (开发中使用) 通过查看api文档发现他们三个(servlet 和GenericSe ...
- 开发servlet三种方式
第一种:实现Servlet接口 ServletDemo类 实现Servlet接口 public class ServletDemo implements Servlet { //初始化该servlet ...
- Servlet实现的三种方法
(1)方法一: //这是第一个实现servlet的方法.使用时限servlet接口的方法来实现,使用的时候须要引用servlet-api.jar package com.lc; import java ...
随机推荐
- ZigBee绑定细节
ZigBee中的绑定由APS层来管理,除了绑定表管理外,APS层还有组表管理.快速地址查找等服务功能.应用层不能直接调用APS层中的数据服务来传输数据,只能通过AF层封装的AD_DataRequest ...
- DEDECMS中,list标签和pagelist标签
列表数据标签:dede:list {dede:list col='' titlelen='' infolen='' imgwidth='' imgheight='' orderby='' pagesi ...
- ▲▲▲▲▲▲▲▲▲▲▲yum源的配置(本地和ftp)▲▲▲▲▲▲▲▲▲▲▲▲▲v
★★★★★★★★★★★★★★★本机yum源★★★★★★★★★★★★★★★★ 1. 首先把DVD里的OS镜像mount处理,如果插入光驱自动mount的话,一般在/media下面,比如RHEL_6.3 ...
- [DevExpress]ChartControl之创建X,Y轴Title示例
关键代码: /// <summary> /// 设置X轴Title /// </summary> /// <param name="chart"> ...
- JavaScript笔记(二)——常用数组、字符串方法的应用
1.将字符串中的字符翻转,比如'hello',翻转成'olleh'. var arr=[]; function reverseString(str) { arr=str.split("&qu ...
- 用AJAX自定义日历
需求分析 在一些购物网站中,都会有促销活动,这些活动都在日历上标注出来,如何通过Ajax让日历 通过读取数据库中的信息,正确的把促销活动标注在日历上,本文通过自定义日历来实现这 个问题. 技术难点 日 ...
- Using jQuery to add a dynamic “Back To Top” floating button with smooth scroll
Ever read a really long blog post or article and then had to scroll all the way up to the top of the ...
- How to install Hadoop
1.How to install Hadoop 3.0.0 http://blog.sina.com.cn/s/blog_4a1f59bf01010kx3.html 2.How to install ...
- 辛星Spring4.x教程开放下载了
下载地址: https://pan.baidu.com/s/1kVSAYeb
- 【转】 GDB 常用调试方法
一.多线程调试 多线程调试可能是问得最多的.其实,重要就是下面几个命令: info thread 查看当前进程的线程. thread <ID> 切换调试的线程为指定ID的线程. break ...