大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動(dòng)力節(jié)點(diǎn)LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 hot資訊 Servlet的作用及開發(fā)步驟

Servlet的作用及開發(fā)步驟

更新時(shí)間:2022-01-04 10:17:47 來源:動(dòng)力節(jié)點(diǎn) 瀏覽988次

1.概念

Servlet:Servlet Apple的簡稱,是服務(wù)器端的程序(代碼,功能實(shí)現(xiàn)),可交互的處理客戶端發(fā)送到服務(wù)端的請求,并完成操作響應(yīng)

動(dòng)態(tài)網(wǎng)頁技術(shù)

JavaWeb程序開發(fā)的基礎(chǔ),JavaEE規(guī)范(一套接口)的一個(gè)組成部分。

2.Servlet作用

接收客戶端請求,完成操作

動(dòng)態(tài)生成網(wǎng)頁(頁面數(shù)據(jù)可變)

將包含操作結(jié)果的動(dòng)態(tài)網(wǎng)頁響應(yīng)給客戶端

3.Servlet開發(fā)步驟

(1)搭建開發(fā)環(huán)境

將Servlet相關(guān)的jar包(lib\servlet-api.jar)配置到classpath中

(2)編寫Servlet

實(shí)現(xiàn)javax.servlet.Servlet

重寫5個(gè)主要方法

在核心的service()方法中編寫輸出語句,打印訪問結(jié)果

MyServlet.java

import java.io.IOException; 
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class MyServlet implements Servlet { 
    @Override
    public void destroy() {
        // TODO Auto-generated method stub 
    } 
    @Override
    public ServletConfig getServletConfig() {
        // TODO Auto-generated method stub
        return null;
    } 
    @Override
    public String getServletInfo() {
        // TODO Auto-generated method stub
        return null;
    } 
    @Override
    public void init(ServletConfig arg0) throws ServletException {
        // TODO Auto-generated method stub 
    } 
    @Override
    public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
        // TODO Auto-generated method stub
		System.out.println("My First servlet"); 
    } 
}

(3)部署Servlet

編譯MyServlet后,將生成的class文件放在WEB-INF/classes文件中

(4)配置Servlet

編寫WEB-INF下項(xiàng)目配置文件web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
 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://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_3_1.xsd"
  version="3.1"
  metadata-complete="true"> 
 <servlet>
	<servlet-name>my</servlet-name>
	<servlet-class>MyServlet</servlet-class>
 </servlet> 
 <servlet-mapping>
	<servlet-name>my</servlet-name>
	<url-pattern>/myservlet</url-pattern>
 </servlet-mapping> 
</web-app>

注意:url-pattern 配置的內(nèi)容就是瀏覽器地址欄輸入的url中項(xiàng)目名稱后資源的內(nèi)容

(5)運(yùn)行測試

啟動(dòng)Tomcat,在瀏覽器地址欄中輸入http://localhost:8080/myweb/myservlet訪問,在Tomcat中打印時(shí)間表示成功

提交申請后,顧問老師會(huì)電話與您溝通安排學(xué)習(xí)

免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 二级毛片全部 | 真人特级毛片免费视频 | 成人人观看的免费毛片 | 成人激情视频在线 | 久久国产免费一区二区三区 | 天天碰免费视频 | 色综合天天色综合 | 欧美亚洲一区二区三区在线 | 国产精品欧美日韩视频一区 | 毛片福利视频 | 手机看片福利久久 | 国产精品日韩欧美久久综合 | 波多野结衣一区二区三区四区 | 淫综合网| 久久综合精品国产一区二区三区 | 国产一区二区视频在线播放 | 亚洲欧美日韩综合一区久久 | 亚欧在线视频 | 四虎影视久久久免费 | 在线观看片成人免费视频 | 欧美亚洲一区二区三区四 | 午夜影院一级片 | 中文字幕免费在线看线人动作大片 | 福利视频网站 | 亚洲精品国产精品精 | 国产欧美日韩看片片在线人成 | 99视频久久 | 97精品久久天干天天蜜 | 中文字幕久久综合伊人 | 久久国产精品ww | 久久五月婷 | 国产不卡视频 | 狠狠色噜狠狠狠狠 | 国产一级精品毛片 | 日本二区视频 | 亚洲精品乱码久久久久久 | 日韩成人 | 久久天天躁夜夜躁狠狠 | 99国产在线视频 | 国产午夜精品一二区理论影院 | 国产一级特黄高清免费大片 |