ServletConfig 对象
生活随笔
收集整理的這篇文章主要介紹了
ServletConfig 对象
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
ServletConfig 對象
問題: 使用 ServletContext 對象可以獲取 web.xml 中的全局配置文件, 在 web.xml 中 每個Servlet 也可以進(jìn)行單獨(dú)的配置,那么該怎么獲取配置信息呢?
解決: 使用 ServletConfig 對象
作用: ServletConfig 對象是 Servlet 的專屬配置對象,每個 Servlet 都單獨(dú)擁有一個 ServletConfig 對象,用來獲取 web.xml 中的配置信息。
使用: 獲取 ServletConfig 對象
? ? ? ? ? ?獲取 web.xml 中 servlet 的配置信息
* ServletConfig對象學(xué)習(xí):
?* ?? ??? ?問題:
?* ?? ??? ??? ?如何獲取在web.xml中給每個servlet單獨(dú)配置的數(shù)據(jù)呢?
?* ?? ??? ?解決:
?* ?? ??? ??? ?使用ServletConfig對象
?* ?? ??? ?使用:
?* ?? ??? ??? ?獲取ServletConfig對象
?* ?? ??? ??? ?獲取web.xml中的配置數(shù)據(jù)
web.xml?
ServletConfigServlet.java
package com.dym.servlet;import java.io.IOException;import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /*** ServletConfig對象學(xué)習(xí):* 問題:* 如何獲取在web.xml中給每個servlet單獨(dú)配置的數(shù)據(jù)呢?* 解決:* 使用ServletConfig對象* 使用:* 獲取ServletConfig對象* 獲取web.xml中的配置數(shù)據(jù)**/ public class ServletConfigServlet extends HttpServlet {@Overrideprotected void service(HttpServletRequest arg0, HttpServletResponse arg1)throws ServletException, IOException {//獲取servletConfig對象ServletConfig sc=this.getServletConfig();//獲取web.xml中的配置數(shù)據(jù)String code=sc.getInitParameter("config");System.out.println(code);} }?
總結(jié)
以上是生活随笔為你收集整理的ServletConfig 对象的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ServletContext 对象
- 下一篇: 使用ServletContext对象完成