云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > (完整版)韩顺平 2011细说Servlet笔记

(完整版)韩顺平 2011细说Servlet笔记

  • 62 次阅读
  • 3 次下载
  • 2025/6/6 4:54:57

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=\

MyFirstServlet com.hsp.MyFirstServlet注意:后面不要带.java④ MyFirstServlet /ABC

服务器调用流程:http://localhost:8088/ABC--->①--->②--->③--->④ 6. 在浏览器中测试 在浏览器中输入

http://localhost:8088/hspweb1/ABC 7. 分析一下自己写可能出现的错误

(1) MyFirstServlet名字不一样 (启动tomcat错误) (2)com.hsp.MyFirstServlet写成 MyFirstServlet.java,会报告500

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文件中:

MyGenericServlet com.hsp.MyGenericServlet

14

MyGenericServlet /MyGenericServlet

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提交分别处理 //回忆

还有一个login.html

post

15

3.4.4小结 get 提交 和 post的提交的区别

① 从安全看 get

② 从提交内容看 get

发中,建议不要大于64k ③ 从速度看 get>post

④ Get可以保留uri中的参数,利于收藏

3.4.5使用ide来开发servlet

使用ide (eclipse[java se]+myeclipse[插件可以jsp/servlet/struts/hibernate/spring..])开发servlet

需求:使用 ide 开发一个servlet ,该servlet 显示 hello,world, 和当前日期 (1)开发步骤:

1)建立web工程

2)在Src 目录下创建了一个包 com.hsp.servlet 3)开发一个Servlet

16

搜索更多关于: (完整版)韩顺平 2011细说Servlet笔记 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com