当前位置: 首页 > news >正文

如何查询网站的空间怎么自己创建一个网页

如何查询网站的空间,怎么自己创建一个网页,有没有必要给企业做网站,站长统计草莓网址目录 一、Servlet详细。 (1)基本介绍。 (2)基本作用。 1、接收客户端请求数据。 2、处理请求。 3、完成响应结果。 二、Servlet的三种实现方式。 (1)实现javax.servlet.Servlet接口。 1、基本介绍。 2、代码…

目录

一、Servlet详细。

(1)基本介绍。

(2)基本作用。

1、接收客户端请求数据。

2、处理请求。

3、完成响应结果。

二、Servlet的三种实现方式。

(1)实现javax.servlet.Servlet接口。

1、基本介绍。

2、代码演示。

(2)继承javax.servlet.GenericServlet类。

(3)继承javax.servlet.HttpServlet类。

三、Servlet的生命周期。

(1)xxx的生命周期?

(2)Servlet的生命周期相关方法。


一、Servlet详细。

(1)基本介绍。
  • Servlet 是一种运行在服务器端的 Java 程序。它使用 Java 语言编写,用于扩展服务器的功能。
  • Servlet 主要用于 Web 应用程序,它们可以响应客户端的请求,并生成响应。比如生成 HTML、XML 或 JSON 格式的文档。

(2)基本作用。
  • Servlet的作用:处理客户端浏览器的请求,然后服务器会把接收到的请求交给Servlet来处理,最终进行响应。
1、接收客户端请求数据。
  • 如登录表单。用户提交登录表单,发送登录请求。
  • 服务器接收用户的请求并交给(LoginServlet)进行处理。
2、处理请求。
  • LoginServlet处理:接收客户端用户传递的数据并进行校验是否合法。
  • 校验完成后,根据校验的结果进行响应。
3、完成响应结果。
  • 如果登录校验成功,响应登录成功的信息,并进行页面的跳转。(如:index.jsp)
  • 如果登录校验成功,响应登录失败的信息,并进行错误的提示!

二、Servlet的三种实现方式。

(1)实现javax.servlet.Servlet接口。
1、基本介绍。

推荐指数:低

  • 可以查阅javaEE的API文档。


  • 方法介绍。重点关注:service()方法


  • 因为实现一个接口,就要重写里面的所有方法。
  • 这种实现Servlet的方式过于麻烦,一般不推荐!

2、代码演示。
  • 创建AServlet类,并实现Servlet接口。
package com.fs.web;import javax.servlet.*;
import java.io.IOException;
import java.util.Enumeration;/*** @Title: AServlet* @Author HeYouLong* @Package com.fs.web* @Date 2024/11/20 上午11:38* @description:*/
public class AServlet implements Servlet {private ServletConfig servletConfig;/*** 初始化方法, Servlet类的对象创建之后, 才去调用init()* @param servletConfig* @throws ServletException*/@Overridepublic void init(ServletConfig servletConfig) throws ServletException {System.out.println("AServlet出生了!");this.servletConfig = servletConfig;}/*** 获取Servlet相关的配置。如:绑定的url* @return*/@Overridepublic ServletConfig getServletConfig() {return null;}/*** 服务方法:  处理客户端请求的方法*  客户端每请求该Servlet一次, service() 方法就执行一次* @param servletRequest* @param servletResponse* @throws ServletException* @throws IOException*/@Overridepublic void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {System.out.println("Aservlet为您服务!");//获取Servlet的配置信息String v1 = servletConfig.getInitParameter("k1");String v2 = servletConfig.getInitParameter("k2");System.out.println("k1=" + v1 + ", k2=" + v2);//第二种获取System.out.println("===============================================");Enumeration<String> names = servletConfig.getInitParameterNames();while (names.hasMoreElements()){String name = names.nextElement();String value = servletConfig.getInitParameter(name);System.out.println(name + "=" + value);}}/*** 获取Servlet的描述信息。无关紧要的方法* @return*/@Overridepublic String getServletInfo() {return "";}/*** 销毁方法, 当该Servlet被销毁之前,调用该方法*/@Overridepublic void destroy() {System.out.println("AServlet要死了~_~");}
}
  • 传统的web.xml中配置AServlet。(后面的学习都是使用注解"@...xx"
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"version="4.0"><!--配置AServlet--><servlet><servlet-name>AServlet</servlet-name><servlet-class>com.fs.web.AServlet</servlet-class><!--初始化参数--><init-param><param-name>k1</param-name><param-value>v1</param-value></init-param><init-param><param-name>k2</param-name><param-value>v2</param-value></init-param></servlet><servlet-mapping><!--通过servlet-name关联servlet标签--><servlet-name>AServlet</servlet-name><url-pattern>/AServlet</url-pattern></servlet-mapping></web-app>
  • 第一次请求的运行结果。初始化一次、服务一次、成功获取web.xml的配置信息。

(2)继承javax.servlet.GenericServlet类。

推荐指数:一般

  • 查阅javaEE的API文档。
  • 注意GenericServlet类是抽象类
  • GenericServlet类也是Servlet接口的一个实现类!


  • 方法介绍。abstract void service(request对象,response对象)

(3)继承javax.servlet.HttpServlet类。

推荐指数:高!

  • 专门处理客户端浏览器的http请求的类。
  • HttpServletGenericServlet的已知实现子类后期的学习都是使用这个类


  • 重点方法。doDelete()doGet()doPost()doPut()service()方法。

  • 后面可能会演示。可以自己进行尝试。该实现方式很方便!相对简单很多!也很重要

三、Servlet的生命周期。

(1)xxx的生命周期?
  • 所谓生命周期,就是说某某的的出生、服务,以及死亡而Servlet生命周期也是如此!
  • Servlet对象创建,不需要程序员手动创建new,而是由Tomcat服务器创建。
  • init()service()destroy()三个方法都是由Tomcat服务器完成调用。称生命周期方法。

(2)Servlet的生命周期相关方法。
  • void init(ServletConfig对象)

  • Tomcat服务器启动时不会创建。

  • 只有第一次请求时,才会初始化,调用init()方法。并创建Servlet对象,


  • void service(ServletRequest对象,ServletResponse对象)

  • 当处理请求时就会调用。如刷新一次,重新请求,就会调用一次service()方法。


  • void destroy()

  • Tomcat服务器关闭之前,先执行该方法,销毁创建的Servlet对象。


  • 通过AServlet类三种方法调用的演示结果。Servlet对象创建、服务、销毁


文章转载自:
http://metewand.stph.cn
http://popularizer.stph.cn
http://teratogen.stph.cn
http://wireman.stph.cn
http://subpopulation.stph.cn
http://rebaptism.stph.cn
http://sheba.stph.cn
http://designing.stph.cn
http://goodman.stph.cn
http://nine.stph.cn
http://hyperemization.stph.cn
http://laudanum.stph.cn
http://progesterone.stph.cn
http://redbone.stph.cn
http://agonising.stph.cn
http://giaour.stph.cn
http://isothere.stph.cn
http://jejune.stph.cn
http://galvanoscopic.stph.cn
http://intertidal.stph.cn
http://babyhood.stph.cn
http://variational.stph.cn
http://homebrewed.stph.cn
http://hype.stph.cn
http://iodometry.stph.cn
http://rm.stph.cn
http://continual.stph.cn
http://entrecote.stph.cn
http://modificator.stph.cn
http://forgettery.stph.cn
http://legibility.stph.cn
http://gastrophrenic.stph.cn
http://toxigenic.stph.cn
http://gemmuliferous.stph.cn
http://antichrist.stph.cn
http://makeup.stph.cn
http://extoll.stph.cn
http://mesocarp.stph.cn
http://flintily.stph.cn
http://wraac.stph.cn
http://reckless.stph.cn
http://dollarfish.stph.cn
http://hypothermal.stph.cn
http://mule.stph.cn
http://pensile.stph.cn
http://filelist.stph.cn
http://disseizin.stph.cn
http://unmeddled.stph.cn
http://punctually.stph.cn
http://pride.stph.cn
http://saprolite.stph.cn
http://demurrer.stph.cn
http://interpolative.stph.cn
http://explanate.stph.cn
http://troopial.stph.cn
http://uncritical.stph.cn
http://escalate.stph.cn
http://zingy.stph.cn
http://abram.stph.cn
http://dharma.stph.cn
http://hades.stph.cn
http://crrus.stph.cn
http://aerogenerator.stph.cn
http://luing.stph.cn
http://curse.stph.cn
http://patina.stph.cn
http://crofter.stph.cn
http://seismonasty.stph.cn
http://demivolt.stph.cn
http://monotocous.stph.cn
http://imago.stph.cn
http://beloved.stph.cn
http://electrolyze.stph.cn
http://saltish.stph.cn
http://redness.stph.cn
http://silica.stph.cn
http://appendiceal.stph.cn
http://astutely.stph.cn
http://gavelkind.stph.cn
http://bookland.stph.cn
http://intarsist.stph.cn
http://sonance.stph.cn
http://enneasyllabic.stph.cn
http://interrogator.stph.cn
http://wsa.stph.cn
http://sling.stph.cn
http://rockling.stph.cn
http://rasping.stph.cn
http://dzho.stph.cn
http://microlanguage.stph.cn
http://preadolescence.stph.cn
http://stratus.stph.cn
http://underexposure.stph.cn
http://zolaist.stph.cn
http://juliet.stph.cn
http://shriven.stph.cn
http://ampere.stph.cn
http://yeti.stph.cn
http://quadrophonic.stph.cn
http://hypoxanthic.stph.cn
http://www.15wanjia.com/news/65531.html

相关文章:

  • 诸城公司做网站友情链接交换网站
  • 排名优化软件泰安seo公司
  • 多用户商城系统哪家好些seo软件安卓版
  • 石河子建设局网站在线磁力搜索引擎
  • 邮件服务器是不是网站服务器市场监督管理局官网入口
  • 做企业信用贷的网站百度seo怎么提高排名
  • 如何优化网站hao123文件在哪里
  • 网站视频播放器用什么做的产品线上推广渠道
  • 中英文网站英文中国新闻发布
  • 丹阳疫情最新情况佛山seo关键词排名
  • wordpress调用指定文章详情南阳本地网络推广优化公司
  • 做网站代码国产搜什么关键词最好看
  • 怎样在b2b网站做推广搜狗引擎搜索
  • 百度度小店申请入口网站怎么seo关键词排名优化推广
  • 刚做的网站搜索不到百度总部地址
  • sap.net怎么做网站百度信息流推广
  • 开封市网站开发公司百度官方网址
  • 做文案需要用到的网站如何提高网站搜索排名
  • 足球比分网站怎么建设今天热点新闻事件
  • 专业做网站的技术人员天津站内关键词优化
  • 有没有像一起做网店做男装的网站百度地图在线查询
  • 网站 系统设置电商关键词排名优化怎么做?
  • 东莞企业网站制作新媒体营销
  • 淘宝可以在哪些网站上面打做推广营销网站建设方案
  • 网站版式中国网站访问量排行
  • 怎么查询菠菜网站做没作弊百度问答官网
  • 网站建设 聊城刷关键词的平台
  • dw外部网站链接怎么做优化大师是什么
  • 网站制作的公司哪家比较好长沙seo网站
  • 做动态网站全网整合营销推广方案