Java Servlets
<html> <head> <title>Introductions</title> </head> <body> <form method="get" action="/servlet/hello"> If you don't mind me asking, what is your name? <input type="text" name="name"/><p/> <input type="submit"/> </form> </body> </html>
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Hello extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String name = req.getParameter("name"); out.println("<html>"); out.println("<head><title>Hello, " + name + "</title></head>"); out.println("<body>"); out.println("Hello, " + name); out.println("</body></html>"); } public String getServletInfo() { return "A servlet that knows the name of the person to whom it's" + "saying hello"; } }
11 of 89