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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ServletContext2

發布時間:2024/10/12 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ServletContext2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

------------ContextServlet.java--------------節選--

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
??// TODO Auto-generated method stub
??request.setCharacterEncoding("GB2312");
??response.setContentType("text/html;charset=gb2312");
??PrintWriter out = response.getWriter();
??ServletContext context = getServletConfig().getServletContext();
??//獲得工程相關信息
??out.println("獲得了工程的相對路徑:"+context.getRealPath("/")+"<br>");
??out.println("獲取了Tomcat的信息: "+context.getServerInfo()+"<br>");
??out.println("獲取了JNDI:"+context.getResource("/")+"<br>");
??out.println("獲取了源程序的相對路徑:"+context.getResourcePaths("/")+"<br>");
??//getInitParameter方法
??String date = context.getInitParameter("date");
??String myclass = context.getInitParameter("class");
??out.println("date is -- "+date+"<br>");
??out.println("class is -- "+myclass+"<br>");
??//集合方法
??Enumeration e = context.getInitParameterNames();
??while(e.hasMoreElements()){
???String pName=(String) e.nextElement();
???String pValue=context.getInitParameter(pName);
???out.println("<br><b>"+pName+"</b>&nbsp;");
???out.println("----- "+pValue+"<br>");
??}
?}

?

?

-------------------web.xml----------------------

<?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_3_0.xsd" id="WebApp_ID" version="3.0">
? <display-name>test4-03</display-name>
? <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>
? <context-param>
? ?<param-name>date</param-name>
? ?<param-value>200</param-value>
? </context-param>
? <context-param>
? ?<param-name>class</param-name>
? ?<param-value>102</param-value>
? </context-param>
? <servlet>
? ?<description>This is the description of my J2EE component</description>
? ?<display-name>This is the display name of my J2EE component</display-name>
? ?<servlet-name>ContextServlet</servlet-name>
? ?<servlet-class>com.ContextServlet</servlet-class>
? ?<load-on-startup>1</load-on-startup>
? </servlet>
? <servlet-mapping>
? ?<servlet-name>ContextServlet</servlet-name>
? ?<url-pattern>/servlet/ContextServlet</url-pattern>
? </servlet-mapping>
</web-app>

轉載于:https://www.cnblogs.com/daimazhang/p/5364994.html

總結

以上是生活随笔為你收集整理的ServletContext2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。