01_9_ServletContext
01_9_ServletContext
1.?例子
public?void?doGet(HttpServletRequest request, HttpServletResponse response)
throws?ServletException, IOException {
?
response.setContentType("text/html;charset=utf-8");
ServletContext application = this.getServletContext();
Integer accessCount = (Integer) application.getAttribute("accessCount");
if?( accessCount == null) {
accessCount = new?Integer(0);
} else?{
accessCount = new?Integer(accessCount.intValue() + 1 );
}
application.setAttribute("accessCount", accessCount);
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println("<HEAD><TITLE>Servelet Context</TITLE></HEAD>");
out.println("<BODY><H1 align=\"CENTER\">"?+ accessCount);
out.println("</H1></BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
轉載于:https://www.cnblogs.com/flyback/p/8817673.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的01_9_ServletContext的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么现在当兵要积分呢
- 下一篇: Intellij IDEA中 Debug