Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Un semplice servlet che elabora richieste get
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.io.*;
- public class WelcomeServlet extends HttpServlet{
- // Elabora richieste "get" dai client
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException
- {
- response.setContentType("text/html");
- PrintWriter out = response.getWriter();
- // Inizio documento XHTML
- out.println("<?xbl version = "1.0"?>");
- out.println("<!DOCTYPE html PUBLIC "-//W3C//DTD "+"XHTML 1.0 Strict//EN" "http://www.w3.org"+"/TR/xhtml1/DTD/xhtml1-strict.dtd">");
- out.println("<html xmlns = "http://www.w3.org/1999/xhtml">");
- // sezione head del docuento
- out.println("<head>");
- out.println("<title>A Simple Servlet Example</title>");
- out.println("</head>");
- // sezione body del documento
- out.println("<body>");
- out.println("<h1>Welcome to Servlets!</h1>");
- out.println("</body>");
- // fine documento XTHML
- out.println("</html>");
- out.close(); //close stream to complete the page
- }
- }
- <?xml version = "1.0"?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <!-- Fig. 13.6: WelcomeServlet.html -->
- <html xmlns = "http://www.w3.org/1999/xhtml">
- <head>
- <title>Handling an HTTP Get Request</title>
- </head>
- <body>
- <form action = "/src/WelcomeServlet.java" method = "get"></form>
- <p><label>Click the button to invoke the servlet
- <input type = "submit" value = "Get HTML Document"/>
- </label></p>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement