当前位置:首页 > (完整版)韩顺平 2011细说Servlet笔记
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 \ 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 \
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. -->
xmlns:xsi=\ xsi:schemaLocation=\http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\ version=\
服务器调用流程:http://localhost:8088/ABC--->①--->②--->③--->④ 6. 在浏览器中测试 在浏览器中输入
http://localhost:8088/hspweb1/ABC 7. 分析一下自己写可能出现的错误
(1)
13
(3)资源名自己写错
http://localhost:8088/hspweb1/错误的资源url-pattern 404错误
补充:如果使用javac 去编译一个java文件,则需要带命令参数 javac –d . java文件
补充: 如何不重启tomcat,就指定去 reload 一个web应用,方法: 进入到 tomcat 的 manager:
点击reload即可. 课堂练习
自己使用实现Servlet接口的方法,开发一个Servlet,该servlet 可以输出自己的名字 在显示当前日期.
3.4.2使用GenericServlet开发servlet
了解即可: 案例:
package com.hsp;
import javax.servlet.*;
import javax.servlet.http.*; import java.io.*;
public class MyGenericServlet extends GenericServlet { public void service(ServletRequest req,
ServletResponse res) throws ServletException, java.io.IOException{ res.getWriter().println(\ } }
将该Servlet部署到web.xml文件中:
14
3.4.3使用继承 HttpServlet 的方法来开发Serlvet
(1)在软件公司 90%都是通过该方法开发.
(2)举例说明; 还是显示 hello,world 当前日期 代码:
package com.hsp;
import javax.servlet.*;
import javax.servlet.http.*; import java.io.*;
public class MyHttpServlet extends HttpServlet { //在HttpServlet 中,设计者对post 提交和 get提交分别处理 //回忆
共分享92篇相关文档