国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

豬八戒做網(wǎng)站靠譜嗎國際最新新聞

豬八戒做網(wǎng)站靠譜嗎,國際最新新聞,龍口網(wǎng)站建設(shè),hao123主頁下載安裝Web應(yīng)用開發(fā) - 實(shí)訓(xùn)三 B Servlet基礎(chǔ) 前言: 零、前期準(zhǔn)備準(zhǔn)備工具創(chuàng)建項(xiàng)目導(dǎo)入 jar 包配置運(yùn)行設(shè)置 一、實(shí)訓(xùn)第一部分第一張圖第二張圖第三張圖 二、實(shí)訓(xùn)第二部分第一張圖第二張圖 前言: eclipse 是不可能用的,并不是說它界面丑,…

Web應(yīng)用開發(fā) - 實(shí)訓(xùn)三 B Servlet基礎(chǔ)

    • 前言:
  • 零、前期準(zhǔn)備
    • 準(zhǔn)備工具
    • 創(chuàng)建項(xiàng)目
      • 導(dǎo)入 jar 包
      • 配置運(yùn)行設(shè)置
  • 一、實(shí)訓(xùn)第一部分
    • 第一張圖
    • 第二張圖
    • 第三張圖
  • 二、實(shí)訓(xùn)第二部分
    • 第一張圖
    • 第二張圖

前言:

eclipse 是不可能用的,并不是說它界面丑,也不是說它難用,而是它實(shí)在不適合我,idea 還能用一用,界面還挺符合我審美的,一些操作也比較合適。

注意:本篇文章使用的是工具是 IDEA,搭配 tomcat 10.1 使用

零、前期準(zhǔn)備

準(zhǔn)備工具

  • 下載 tomcat 10.1 并安裝

下載地址:https://tomcat.apache.org/download-10.cgi
在這里插入圖片描述

創(chuàng)建項(xiàng)目

直接新建項(xiàng)目,選擇 Jakara EE,模板為“Web 應(yīng)用程序”,接下來就直接下一步,創(chuàng)建。
在這里插入圖片描述

導(dǎo)入 jar 包

  1. 找到 tomcat 的安裝目錄
    (默認(rèn)是:C:\Program Files\Apache Software Foundation\Tomcat 10.1)
    在這里插入圖片描述
  2. 回到 idea 中點(diǎn)擊左上角的“文件” -> “項(xiàng)目結(jié)構(gòu)”
    在這里插入圖片描述
  3. 點(diǎn)擊左側(cè)的 “庫” -> 點(diǎn)擊 “+” -> 選擇 java
    在這里插入圖片描述
  4. 在彈出來的窗口中找到剛剛找到的 tomcat 安裝目錄,并找到 lib 文件夾下的 “servlet-api.jar ”,然后確認(rèn)就好了
    在這里插入圖片描述

配置運(yùn)行設(shè)置

  1. 點(diǎn)擊上方的“當(dāng)前文件”,選擇 “編輯配置”
    在這里插入圖片描述
  2. 點(diǎn)擊左上角的 “+”,找到 “Tomcat 服務(wù)器”本地
    在這里插入圖片描述
  3. 點(diǎn)擊 “部署”,選擇 “工件”,并點(diǎn)擊 “Servlet_war_exploded”
    在這里插入圖片描述
    在這里插入圖片描述
  4. 將下面的 “/Servlet_war_exploded” 改為 “/chapter03”
    在這里插入圖片描述
    基本工作就到此結(jié)束,開始進(jìn)入正題!!!

一、實(shí)訓(xùn)第一部分

第一張圖

在圖中目錄創(chuàng)建 “HelloWorldServlet.java” ,代碼如下:

package com.example.servlet;import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;import java.io.*;@WebServlet(name = "HelloWorldServlet", value = "/cn/itcast/firstapp/servlet/HelloWorldServlet")
public class HelloWorldServlet extends GenericServlet {public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {// 得到輸出流 PrinterWriter 對象,Servlet 使用輸出流來產(chǎn)生響應(yīng)PrintWriter out = response.getWriter();// 使用輸出流對象向客戶端發(fā)送字符數(shù)據(jù)out.println("Hello World");}
}

點(diǎn)擊右上角的三角形就可以運(yùn)行項(xiàng)目了
在這里插入圖片描述
在瀏覽器中打開 http://localhost:8080/chapter03/cn/itcast/firstapp/servlet/HelloWorldServlet
效果圖如下所示
在這里插入圖片描述

第二張圖

將 “HelloWorldServlet.java” 中的代碼修改成下面:

package com.example.servlet;import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;@WebServlet(name = "HelloWorldServlet", value = "/HelloWorldServlet")
public class HelloWorldServlet extends GenericServlet {public void init(ServletConfig config) throws ServletException {System.out.println("init methed is called");}public void service(ServletRequest request, ServletResponse response) throws ServletException {System.out.println("Hello World");}public void destroy() {System.out.println("destroy method is called");}
}

重新運(yùn)行程序

在這里插入圖片描述

在瀏覽器中打開 http://localhost:8080/chapter03/HelloWorldServlet

可以看到終端,這邊是我們需要的截圖(只需要截終端的那部分)
在這里插入圖片描述

第三張圖

分別在圖中的兩個(gè)路徑中創(chuàng)建 “RequestMethodServlet.java” 和 “form.html”

在這里插入圖片描述

RequestMethodServlet.java 文件中的代碼如下:

package com.example.servlet;import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;import java.io.*;@WebServlet(name = "RequestMethodServlet", value = "/RequestMethodServlet")
public class RequestMethodServlet extends HttpServlet {public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException {PrintWriter out = response.getWriter();out.write("this is doGet method");}public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException {PrintWriter out = response.getWriter();out.write("this is doPost method");}
}

form.html 文件中的代碼如下:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<form action="/chapter03/RequestMethodServlet" method="post">姓名<input type="text" name="name"/><br/>密碼<input type="text" name="psw"/><br/><input type="submit" value="提交"/>
</form>
</body>
</html>

在瀏覽器中打開 http://localhost:8080/chapter03/form.html 截圖,點(diǎn)擊“提交”后截圖
在這里插入圖片描述
在這里插入圖片描述

二、實(shí)訓(xùn)第二部分

第一張圖

在如圖文件夾中創(chuàng)建 “TestServlet02.java”

在這里插入圖片描述
TestServlet02.java 文件代碼如下

package com.example.servlet;import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebInitParam;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;import java.io.IOException;
import java.io.PrintWriter;@WebServlet(name = "TestServlet02", value = "/TestServlet02",initParams = {@WebInitParam(name = "encoding", value = "UTF-8")})
public class TestServlet02 extends HttpServlet {protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {PrintWriter out = response.getWriter();// 獲得 ServletConfig 對象ServletConfig config = this.getServletConfig();// 獲得參數(shù)名為 encoding 對應(yīng)的參數(shù)值String param = config.getInitParameter("encoding");out.println("encoding=" + param);}protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}

在瀏覽器中打開 http://localhost:8080/chapter03/TestServlet02 并截圖

在這里插入圖片描述

第二張圖

在如圖路徑中新建文件 “TestServlet03.java”

在這里插入圖片描述
TestServlet03.java 文件代碼如下:

package com.example.servlet;import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;@WebServlet("/TestServlet03")
public class TestServlet03 extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType("text/html; charset=utf-8");PrintWriter out = response.getWriter();// 得到 ServletContext 對象ServletContext context = this.getServletContext();// 得到包含所有初始化參數(shù)名的Enumeration 對象Enumeration<String> paramNames = context.getInitParameterNames();out.println("all the paramName and paramValue are following: ");// 遍歷所有的初始化參數(shù)名,得到相應(yīng)的參數(shù)值并打印while (paramNames.hasMoreElements()) {String name = paramNames.nextElement();String value = context.getInitParameter(name);out.println(name + ": " + value);out.println("<br />");}}public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}

在如圖文件 “web.xml” 中添加如圖部分代碼

    <context-param><param-name>companyName</param-name><param-value>itcast</param-value></context-param><context-param><param-name>address</param-name><param-value>beijing</param-value></context-param>

在這里插入圖片描述
在瀏覽器中打開 http://localhost:8080/chapter03/TestServlet03 并截圖

在這里插入圖片描述

恭喜,?實(shí)訓(xùn)三到此結(jié)束!!!

http://aloenet.com.cn/news/30698.html

相關(guān)文章:

  • 網(wǎng)站建設(shè)與開發(fā)做什么足球世界排名國家最新
  • 商城購物網(wǎng)站建設(shè)方案短視頻營銷策略
  • 東莞手機(jī)網(wǎng)站建設(shè)網(wǎng)站怎么優(yōu)化關(guān)鍵詞
  • 遵義做什么網(wǎng)站好seo門戶
  • 石家莊網(wǎng)站運(yùn)營公司最新新聞事件
  • 口碑好的常州做網(wǎng)站app開發(fā)用什么軟件
  • 可以充值的網(wǎng)站怎么做互聯(lián)網(wǎng)金融
  • 煙臺網(wǎng)站推廣排名競價(jià)推廣代運(yùn)營
  • 做一個(gè)類似京東的網(wǎng)站免費(fèi)發(fā)布推廣的平臺
  • 南京制作網(wǎng)站公司網(wǎng)站seo1視頻發(fā)布會
  • php動(dòng)態(tài)網(wǎng)站開發(fā)案例教程china東莞seo
  • 蘇州網(wǎng)站制作設(shè)計(jì)西安網(wǎng)絡(luò)seo公司
  • wordpress限制ip訪問次數(shù)網(wǎng)站seo報(bào)價(jià)
  • 網(wǎng)站開發(fā)大學(xué)是什么專業(yè)中國目前最好的搜索引擎
  • wordpress怎么掙錢常見的系統(tǒng)優(yōu)化軟件
  • 蘇州實(shí)力做網(wǎng)站公司人員優(yōu)化方案怎么寫
  • 做微商進(jìn)哪個(gè)網(wǎng)站安全蟻坊軟件輿情監(jiān)測系統(tǒng)
  • 網(wǎng)頁設(shè)計(jì)與制作教程西北工業(yè)大學(xué)廣州網(wǎng)站優(yōu)化步驟
  • 如何做高大上的網(wǎng)站 知乎企業(yè)營銷網(wǎng)站建設(shè)系統(tǒng)
  • 企業(yè)網(wǎng)站ppt怎么做百度搜索資源平臺官網(wǎng)
  • 如何做搜索引擎網(wǎng)站百度網(wǎng)站怎么提升排名
  • 什么是網(wǎng)站維護(hù)中營銷運(yùn)營主要做什么
  • 互聯(lián)網(wǎng)行業(yè)分為哪幾類排名優(yōu)化方法
  • 提交網(wǎng)站汕頭seo推廣
  • 微信公眾號平臺網(wǎng)站開發(fā)百度天眼查公司
  • 用ps怎樣做網(wǎng)站文字logo廣豐網(wǎng)站seo
  • 個(gè)人怎么做貸款網(wǎng)站求購買鏈接
  • 網(wǎng)站權(quán)重高+做別的關(guān)鍵詞百度應(yīng)用下載安裝
  • 學(xué)做效果圖網(wǎng)站有哪些軟件有哪些網(wǎng)站建站方式有哪些
  • 有沒有做數(shù)學(xué)題掙錢的網(wǎng)站艾滋病多久可以查出來