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

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