[ Team LiB ] 11.5 Using Scopes from
[ Team LiB ] 11.5 Using Scopes from Servlets Chapter 3 discussed the various scopes in which beans can live. Although these scopes are usually accessed by setting the scope field in a jsp:useBean tag, they can also be accessed through scriptlets or through code in a servlet. Listing 11.6 shows a servlet with a counter, which works much like the JSP in Listing 3.8 did. Listing 11.6 A servlet with a page counter package com.awl.jspblog.ch11; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Counter1 extends HttpServlet { private int count; public void init(ServletConfig sc) throws ServletException { super.init(sc); count = 0; } public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException,ServletException { handle(req,res); } public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException,ServletException { handle(req,res); } public void handle(HttpServletRequest req, HttpServletResponse res) throws IOException,ServletException { res.setStatus(res.SC_OK); res.setContentType(”text/html”); PrintWriter out = res.getWriter(); out.println(”“); out.println(”
Quick Hint: If you are looking for best quality webspace to host and run your tomcat application check Vision tomcat hosting services