You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Logic.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10. import javax.servlet.ServletException;
  11. import javax.servlet.annotation.WebServlet;
  12. import javax.servlet.http.HttpServlet;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. /**
  16. *
  17. * @author Edi
  18. */
  19. @WebServlet(urlPatterns = {"/Logic"})
  20. public class Logic extends HttpServlet {
  21. /**
  22. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  23. * methods.
  24. *
  25. * @param request servlet request
  26. * @param response servlet response
  27. * @throws ServletException if a servlet-specific error occurs
  28. * @throws IOException if an I/O error occurs
  29. */
  30. Game g = new Game();
  31. String context = "";
  32. public void init() {
  33. g.setVariables();
  34. }
  35. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  36. throws ServletException, IOException, Exception {
  37. response.setContentType("text/html;charset=UTF-8");
  38. try (PrintWriter out = response.getWriter()) {
  39. /* TODO output your page here. You may use following sample code. */
  40. out.println("<html><body><p>" + context + "</p></body></html>");
  41. if (request.getParameter("alexaText") != null) {
  42. context = context + "<br><br>" + request.getParameter("alexaText");
  43. }
  44. String input = request.getParameter("intent");
  45. if (request.getParameter("slot") != null) {
  46. input = input + " " + request.getParameter("slot");
  47. }
  48. if(input != null)
  49. {
  50. g.setInput(input);
  51. g.play();
  52. }
  53. }
  54. }
  55. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  56. /**
  57. * Handles the HTTP <code>GET</code> method.
  58. *
  59. * @param request servlet request
  60. * @param response servlet response
  61. * @throws ServletException if a servlet-specific error occurs
  62. * @throws IOException if an I/O error occurs
  63. */
  64. @Override
  65. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  66. throws ServletException, IOException {
  67. response.setIntHeader("Refresh", 5);
  68. try {
  69. processRequest(request, response);
  70. } catch (Exception ex) {
  71. Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex);
  72. }
  73. }
  74. /**
  75. * Handles the HTTP <code>POST</code> method.
  76. *
  77. * @param request servlet request
  78. * @param response servlet response
  79. * @throws ServletException if a servlet-specific error occurs
  80. * @throws IOException if an I/O error occurs
  81. */
  82. @Override
  83. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  84. throws ServletException, IOException {
  85. response.setIntHeader("Refresh", 5);
  86. try {
  87. processRequest(request, response);
  88. } catch (Exception ex) {
  89. Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex);
  90. }
  91. }
  92. /**
  93. * Returns a short description of the servlet.
  94. *
  95. * @return a String containing servlet description
  96. */
  97. @Override
  98. public String getServletInfo() {
  99. return "Short description";
  100. }// </editor-fold>
  101. }