public class SampleServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
ServletContext context = this.getServletContext();
context.setAttribute("name1","なまえ1");
context.setAttribute("name2","なまえ2");
context.setAttribute("name3","なまえ3");
response.setContentType("text/html;charset=Windows-31J");
PrintWriter out = response.getWriter();
out.println("<html><body>");
Enumeration e = context.getAttributeNames();
while( e.hasMoreElements() ) {
String name = (String)e.nextElement();
out.println( name + "=" + context.getAttribute(name) + "<br>");
}
out.println("</body></html>");
}
}
|