Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  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. package ServletiPackage;
  7.  
  8. import java.io.IOException;
  9. import java.io.PrintWriter;
  10. import javax.servlet.ServletException;
  11. import javax.servlet.http.HttpServlet;
  12. import javax.servlet.http.HttpServletRequest;
  13. import javax.servlet.http.HttpServletResponse;
  14.  
  15. /**
  16. *
  17. * @author Student
  18. */
  19. public class PrviServlet extends HttpServlet {
  20.  
  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. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  31. throws ServletException, IOException {
  32. response.setContentType("text/html;charset=UTF-8");
  33. //
  34. // PrintWriter out = response.getWriter();
  35. // String pojam= request.getParameter("pojam");
  36. // String pretrazivac = request.getParameter("pretrazivac");
  37. //
  38. //
  39. // try {
  40. // /* TODO output your page here. You may use following sample code. */
  41. // out.println("<!DOCTYPE html>");
  42. // out.println("<html>");
  43. // out.println("<head>");
  44. // out.println("<title>Servlet PrviServlet</title>");
  45. // out.println("</head>");
  46. // out.println("<body>"
  47. // + "Pojam za pretragu:" +pojam
  48. // + "<br> <div> Odabrali ste pretrazivac:"+pretrazivac+"</div>"
  49. // + ""
  50. // + ""
  51. // + "");
  52. //
  53. // out.println("</body>");
  54. // out.println("</html>");
  55. // }
  56. // catch
  57. // (Exception E)
  58. // {}
  59. }
  60.  
  61. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  62. /**
  63. * Handles the HTTP <code>GET</code> method.
  64. *
  65. * @param request servlet request
  66. * @param response servlet response
  67. * @throws ServletException if a servlet-specific error occurs
  68. * @throws IOException if an I/O error occurs
  69. */
  70. @Override
  71. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  72. throws ServletException, IOException {
  73. processRequest(request, response);
  74.  
  75. PrintWriter out = response.getWriter();
  76. String pojam= request.getParameter("pojam");
  77. String pretrazivac = request.getParameter("pretrazivac");
  78.  
  79.  
  80. try {
  81. /* TODO output your page here. You may use following sample code. */
  82. out.println("<!DOCTYPE html>");
  83. out.println("<html>");
  84. out.println("<head>");
  85. out.println("<title>Servlet PrviServlet</title>");
  86. out.println("</head>");
  87. out.println("<body>"
  88. + "Pojam za pretragu:" +pojam
  89. + "<br> <div> Odabrali ste pretrazivac:"+pretrazivac+"</div>"
  90. + " <head>\n" +
  91. " <title>Internet pretrazivanje</title>\n" +
  92. " <meta charset=\"UTF-8\">\n" +
  93. " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
  94. " </head>\n" +
  95. " <body>\n" +
  96. " <form action=\"PrviServlet\">\n" +
  97. " <h2>Internet pretrazivanje</h2>\n" +
  98. " \n" +
  99. " Pojam za pretragu:<input name=\"pojam\" type=\"text\" >\n" +
  100. " \n" +
  101. " \n" +
  102. " <br>\n" +
  103. " <input type=\"radio\" name=\"pretrazivac\" value=\"Google\"> Google<br>\n" +
  104. " <input type=\"radio\" name=\"pretrazivac\" value=\"Firefox\" > Firefox<br>\n" +
  105. " <input type=\"radio\" name=\"pretrazivac\" value=\"yahoo\"> yahoo<br>\n" +
  106. " <button type=\"submit\">Pretraga</button>\n" +
  107. " </form>\n" +
  108. " </body>"
  109. + ""
  110. + "");
  111.  
  112. out.println("</body>");
  113. out.println("</html>");
  114. }
  115. catch
  116. (Exception E)
  117. {}
  118. }
  119.  
  120. /**
  121. * Handles the HTTP <code>POST</code> method.
  122. *
  123. * @param request servlet request
  124. * @param response servlet response
  125. * @throws ServletException if a servlet-specific error occurs
  126. * @throws IOException if an I/O error occurs
  127. */
  128. @Override
  129. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  130. throws ServletException, IOException {
  131. processRequest(request, response);
  132. }
  133.  
  134. /**
  135. * Returns a short description of the servlet.
  136. *
  137. * @return a String containing servlet description
  138. */
  139. @Override
  140. public String getServletInfo() {
  141. return "Short description";
  142. }// </editor-fold>
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement