-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab6_2.txt
27 lines (22 loc) · 857 Bytes
/
lab6_2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//RedirectServlet.java
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/redirectServlet")
public class RedirectServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Get the URL entered by the user
String url = request.getParameter("url");
// Redirect to the specified URL
if (url != null && !url.trim().isEmpty()) {
response.sendRedirect(url);
} else {
response.getWriter().println("Invalid URL");
}
}
}