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.6KB

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 = {"/IO"})
  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. try (PrintWriter out = response.getWriter()) {
  38. /* TODO output your page here. You may use following sample code. */
  39. if(request.getParameter("alexaText") != null) {
  40. context = request.getParameter("alexaText");
  41. }
  42. out.println(context);
  43. String input = request.getParameter("intent");
  44. if (request.getParameter("slot") != null) {
  45. input = input + " " + request.getParameter("slot");
  46. }
  47. if(input != null)
  48. {
  49. g.setInput(input);
  50. g.play();
  51. }
  52. }
  53. }
  54. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  55. /**
  56. * Handles the HTTP <code>GET</code> method.
  57. *
  58. * @param request servlet request
  59. * @param response servlet response
  60. * @throws ServletException if a servlet-specific error occurs
  61. * @throws IOException if an I/O error occurs
  62. */
  63. @Override
  64. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  65. throws ServletException, IOException {
  66. response.setIntHeader("Refresh", 2);
  67. try {
  68. processRequest(request, response);
  69. } catch (Exception ex) {
  70. Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex);
  71. }
  72. }
  73. /**
  74. * Handles the HTTP <code>POST</code> method.
  75. *
  76. * @param request servlet request
  77. * @param response servlet response
  78. * @throws ServletException if a servlet-specific error occurs
  79. * @throws IOException if an I/O error occurs
  80. */
  81. @Override
  82. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  83. throws ServletException, IOException {
  84. response.setIntHeader("Refresh", 2);
  85. try {
  86. processRequest(request, response);
  87. } catch (Exception ex) {
  88. Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex);
  89. }
  90. }
  91. /**
  92. * Returns a short description of the servlet.
  93. *
  94. * @return a String containing servlet description
  95. */
  96. @Override
  97. public String getServletInfo() {
  98. return "Short description";
  99. }// </editor-fold>
  100. }