Advertisement
sergAccount

Untitled

Apr 11th, 2021
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.58 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 com.mycompany.service;
  7.  
  8. import java.io.IOException;
  9. import java.io.PrintWriter;
  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.  *
  18.  * @author Admin
  19.  */
  20. @WebServlet(name = "MyRedirectServlet", urlPatterns = {"/MyRedirectServlet"})
  21. public class MyRedirectServlet extends HttpServlet {
  22.  
  23.     /**
  24.      * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  25.      * methods.
  26.      *
  27.      * @param request servlet request
  28.      * @param response servlet response
  29.      * @throws ServletException if a servlet-specific error occurs
  30.      * @throws IOException if an I/O error occurs
  31.      */
  32.     protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  33.        
  34.         // редирект запроса - sendRedirect (не сохраняются параметра)
  35.         response.sendRedirect("http://google.com");
  36.     }
  37.  
  38.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  39.     /**
  40.      * Handles the HTTP <code>GET</code> method.
  41.      *
  42.      * @param request servlet request
  43.      * @param response servlet response
  44.      * @throws ServletException if a servlet-specific error occurs
  45.      * @throws IOException if an I/O error occurs
  46.      */
  47.     @Override
  48.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  49.             throws ServletException, IOException {
  50.         processRequest(request, response);
  51.     }
  52.  
  53.     /**
  54.      * Handles the HTTP <code>POST</code> method.
  55.      *
  56.      * @param request servlet request
  57.      * @param response servlet response
  58.      * @throws ServletException if a servlet-specific error occurs
  59.      * @throws IOException if an I/O error occurs
  60.      */
  61.     @Override
  62.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  63.             throws ServletException, IOException {
  64.         processRequest(request, response);
  65.     }
  66.  
  67.     /**
  68.      * Returns a short description of the servlet.
  69.      *
  70.      * @return a String containing servlet description
  71.      */
  72.     @Override
  73.     public String getServletInfo() {
  74.         return "Short description";
  75.     }// </editor-fold>
  76.  
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement