/**Servlet generating it's environment variables and sends them marked up with HTML. * Internet Programming 2 - Course * @author Martin Carlsson */ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; import mixer.*; public class EnvironmentVariablesHTML extends HttpServlet { private String htmlFileName ="enviroment-variables-html.htm"; private static String htmlFile = null; private static String servletRoot = "/enviroment-variables-html"; public void init() { if(htmlFile == null) { htmlFile = Mixer.getContent(new File(getServletContext().getRealPath(servletRoot+"\\"+htmlFileName))); } } public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { Mixer m = new Mixer(htmlFile); res.setContentType("text/html"); PrintWriter out = res.getWriter(); m.add("","_m_",req.getServerName() + " on port " + req.getServerPort() ); m.add("","_m_","_________________________Enviroment Variables_________________________"); Map environmentVariables = System.getenv(); for (Iterator> iter = environmentVariables.entrySet().iterator(); iter.hasNext(); ) { Map.Entry entry = iter.next(); m.add("","_m_",entry.getKey() + " = " + entry.getValue()); } out.println(m.getMix()); } } // End class EnvironmentVariablesHTML