黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

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

Servlet的作用及開發步驟

更新時間:2022-01-04 10:17:47 來源:動力節點 瀏覽943次

1.概念

Servlet:Servlet Apple的簡稱,是服務器端的程序(代碼,功能實現),可交互的處理客戶端發送到服務端的請求,并完成操作響應

動態網頁技術

JavaWeb程序開發的基礎,JavaEE規范(一套接口)的一個組成部分。

2.Servlet作用

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

動態生成網頁(頁面數據可變)

將包含操作結果的動態網頁響應給客戶端

3.Servlet開發步驟

(1)搭建開發環境

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

(2)編寫Servlet

實現javax.servlet.Servlet

重寫5個主要方法

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

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下項目配置文件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 配置的內容就是瀏覽器地址欄輸入的url中項目名稱后資源的內容

(5)運行測試

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

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 日韩在线专区 | 天天干天天草 | 手机成人在线视频 | 国产一级在线 | 一区二区三区精品国产欧美 | 日本不卡免费在线 | 九九精品视频在线播放8 | 成年人色网站 | 五月天堂网 | 羞羞视频免费网站在线 | 欧美88888在线观看 | 嫩模被xxxx视频在线观看 | 农村妇女又色黄一级毛片 | 亚洲区一二三四区2021 | 香蕉视频ww| 色婷婷狠狠久久综合五月 | 亚洲欧美日韩国产专区一区 | 成人在免费视频手机观看网站 | 人人射人人 | 日本在线观看一区二区三区 | 中文字幕一区视频 | 中文字幕美日韩在线高清 | 激情五月网站 | 欧美成人手机在线视频 | 亚洲一区区 | 久久天堂夜夜一本婷婷麻豆 | 亚洲欧美在线观看首页 | 亚洲精品人成网在线播放影院 | 日韩欧美中文字幕一区二区三区 | 丁香五月缴情综合网 | 91短视频在线观看免费最新 | 日本乱仑| 一级a毛片免费观看久久精品 | 日韩欧美不卡一区二区三区 | 欧美色欧美亚洲另类二区精品 | 成人午夜在线观看 | 老司机精品久久 | 亚洲第一网址 | 国产黄色大片在线观看 | 午夜影视在线免费观看 | 亚洲va欧美va |