MyBean.java: package myapp; public class MyBean { private String stringValue; public void setStringValue(String stringValue) { this.stringValue = stringValue; } public String getStringValue() { return stringValue; } } CompanyNameServlet.java: package myapp; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class CompanyNameServlet extends HttpServlet { private String companyName; private String color; public void init(ServletConfig config) throws ServletException { super.init(config); companyName = config.getInitParameter("companyName"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { color = request.getParameter("color"); if (color == null) { color = "black"; } response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.print("<head>"); out.print("<title>Company Name Servlet</title>"); out.println("</head>"); out.println("<body>"); out.print("<font color=" + color + "><h1>" + companyName); out.println("</h1></font>"); out.println("<hr>"); out.println("</body>"); out.println("</html>"); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } } |