日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Servlet的配置

發(fā)布時(shí)間:2023/12/1 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Servlet的配置 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1,基本配置

<!-- Servlet類的配置 --><servlet><servlet-name>sq</servlet-name><servlet-class>beyond.servlet.QuickStartServlet</servlet-class></servlet><!-- Servlet的虛擬路徑的配置 --> <servlet-mapping><servlet-name>sq</servlet-name><url-pattern>/beyond</url-pattern> <!-- 最后訪問的就是這個(gè) --></servlet-mapping>

其中url-pattern的配置方式
1)完全匹配
訪問的資源與配置的資源完全相同才能訪問的到

<url-pattern>/beyond</url-pattern>

2)目錄匹配
/虛擬的目錄…/*

<url-pattern>/wsq/qb/yy/*</url-pattern> //只要是訪問的是wsq/qb/yy下的任何資源都可以訪問到

3)擴(kuò)展名匹配
*.擴(kuò)展名

<url-pattern>*.wsq</url-pattern>
注意:第二種跟第三種不要混用
例如:/wsq/qb/yy/*.wsq 這是錯(cuò)誤的

2,服務(wù)器啟動(dòng)實(shí)例化Servlet配置

Servlet默認(rèn)第一次訪問的時(shí)候創(chuàng)建
當(dāng)servlet的配置時(shí),加上一個(gè)配置<load-on-startup>3</load-on-startup>的時(shí)候,對(duì)象在服務(wù)器啟動(dòng)時(shí)就創(chuàng)建,數(shù)字(正整數(shù))代表優(yōu)先級(jí),越小優(yōu)先級(jí)越高。

3,缺省Servlet

可以將url-pattern配置一個(gè)/,<url-pattern>/</url-pattern>,代表該servlet 是缺省的servlet(當(dāng)你訪問資源地址所以的servlet都不匹配時(shí),缺省的servlet負(fù)責(zé)處理),其實(shí),web應(yīng)用中所有的資源響應(yīng)都是servlet負(fù)責(zé)的,包括靜態(tài)資源

4,歡迎界面

在WEB13這個(gè)項(xiàng)目工程下面的WebContent下創(chuàng)建一個(gè)index.html,當(dāng)?shù)刂吩L問http://localhost:8080/WEB13/,只訪問到項(xiàng)目名稱的時(shí)候,就會(huì)自動(dòng)訪問index.html該頁面。
優(yōu)先級(jí)如下所示:
<welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list>

其實(shí)當(dāng)把項(xiàng)目工程放到TomCat上,訪問的地址為:http://localhost:8080/WEB13/wsq

這里的WEB13是項(xiàng)目的文件名;

這里的wsq是WEB13 ----->WebContent ------>WEB-INF ----->web.xml -----><url-pattern>/wsq</url-pattern>這個(gè)路徑名稱,它找<servlet-name>sq</servlet-name>,

然后再找

<servlet-class>beyond.servlet.QuickStartServlet</servlet-class>

最后找到該包。

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"><display-name>WEB13</display-name><!-- Servlet類的配置 --><servlet><servlet-name>sq</servlet-name><servlet-class>beyond.servlet.QuickStartServlet</servlet-class><init-param><param-name>url</param-name><param-value>beyondsq</param-value></init-param><load-on-startup>3</load-on-startup></servlet><!-- Servlet的虛擬路徑的配置 --> <servlet-mapping><servlet-name>sq</servlet-name><url-pattern>/wsq</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list> </web-app>

總結(jié)

以上是生活随笔為你收集整理的Servlet的配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。