Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. // Un semplice servlet che elabora richieste get
  2.  
  3. import javax.servlet.*;
  4. import javax.servlet.http.*;
  5. import java.io.*;
  6.  
  7. public class WelcomeServlet extends HttpServlet{
  8. // Elabora richieste "get" dai client
  9. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  10. throws ServletException, IOException
  11. {
  12. response.setContentType("text/html");
  13. PrintWriter out = response.getWriter();
  14.  
  15. // Inizio documento XHTML
  16. out.println("<?xbl version = "1.0"?>");
  17.  
  18. out.println("<!DOCTYPE html PUBLIC "-//W3C//DTD "+"XHTML 1.0 Strict//EN" "http://www.w3.org"+"/TR/xhtml1/DTD/xhtml1-strict.dtd">");
  19. out.println("<html xmlns = "http://www.w3.org/1999/xhtml">");
  20.  
  21. // sezione head del docuento
  22. out.println("<head>");
  23. out.println("<title>A Simple Servlet Example</title>");
  24. out.println("</head>");
  25.  
  26. // sezione body del documento
  27. out.println("<body>");
  28. out.println("<h1>Welcome to Servlets!</h1>");
  29. out.println("</body>");
  30.  
  31. // fine documento XTHML
  32. out.println("</html>");
  33. out.close(); //close stream to complete the page
  34. }
  35. }
  36.  
  37. <?xml version = "1.0"?>
  38. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  39. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  40.  
  41. <!-- Fig. 13.6: WelcomeServlet.html -->
  42.  
  43. <html xmlns = "http://www.w3.org/1999/xhtml">
  44. <head>
  45. <title>Handling an HTTP Get Request</title>
  46. </head>
  47.  
  48. <body>
  49. <form action = "/src/WelcomeServlet.java" method = "get"></form>
  50.  
  51. <p><label>Click the button to invoke the servlet
  52. <input type = "submit" value = "Get HTML Document"/>
  53. </label></p>
  54.  
  55. </form>
  56. </body>
  57. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement