⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contextgetattribute.java

📁 Java程序设计 Jsp/Servlet开发
💻 JAVA
字号:
package ServletApi;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ContextGetAttribute extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
	res.setContentType("text/html;charSet=gb2312");
	PrintWriter out = res.getWriter();
	out.println("<HTML><TITLE>SetContextAttribute</TITLE><BODY>");
	out.println("<H4>ServletContext example - Attribute Getter</H4><HR>");
	ServletContext sc = getServletContext();

	int calledCount = 0; 
	if (sc.getAttribute("calledCount") != null) {
		//取得servletContext里calledCount属性的值
		Integer tempCount = (Integer)sc.getAttribute("calledCount");
		calledCount = tempCount.intValue(); 
	}
	out.println("我们得到的'calledCount'属性值是: " + calledCount + "<BR>");
	out.println("</BODY><HTML>");
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -