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 ...
随机推荐
- C#中Predicate<T>与Func<T, bool>泛型委托的用法实例
本文以实例形式分析了C#中Predicate<T>与Func<T, bool>泛型委托的用法,分享给大家供大家参考之用.具体如下: 先来看看下面的例子: 1 2 3 4 5 6 ...
- (转)实战Memcached缓存系统(6)Memcached CAS的多线程程序实例
1. 源程序 package com.sinosuperman.memcached; import java.io.IOException; import java.net.InetSocketAdd ...
- UVaLive 7361(矩阵快速幂)
题意:矩阵快速幂求斐波那契数列. 分析:
- lex&yacc4
yacc: we cannt use the $$ value dirictly. we need get it irrotly;
- DWZ 刷新 dialog
DWZ刷新dialog: 1,在删除按钮上添加callback属性;如:(callback="dialogAjax") <a class="delImg" ...
- PHP、Java、C#实现URI参数签名算法,确保应用与REST服务器之间的安全通信,防止Secret Key盗用、数据篡改等恶意攻击行为
简介 应用基于HTTP POST或HTTP GET请求发送Open API调用请求时,为了确保应用与REST服务器之间的安全通信,防止Secret Key盗用.数据篡改等恶意攻击行为,REST服务器使 ...
- 使用node.js抓取有路网图书信息(原创)
之前写过使用python抓取有路网图书信息,见http://www.cnblogs.com/dyf6372/p/3529703.html. 最近想学习一下Node.js,所以想试试手,比较一下http ...
- [ Database ] [ Sybase ] [ SQLServer ] sybase 與SQL Server的界接方式
目前我們有個專案Server A安裝了 SQL Server 2012,有個需求需要連線到另外一台Server B上的 Sybase 12.5的view, 先前試過了很多方法都無法連通.主要的原因是因 ...
- [Testing] 測試電子原文書
測試電子原文書 http://files.cnblogs.com/vincentmylee/SoftwareTesting2ndEdition.7z
- WPF 多线程处理(2)
WPF 多线程处理(1) WPF 多线程处理(2) WPF 多线程处理(3) WPF 多线程处理(4) WPF 多线程处理(5) WPF 多线程处理(6) WPF UI 设计需要自动适应窗体大小,那么 ...