I have the following jsp
where I need to modify a specific part of my current url
String path = request.getRequestURL().toString();
...
response.sendRedirect("https://new.user.SAME.SAME/main.jsp");
I would like to take the XXX
part of my current url
and put it in the sendRedirect
link.
For an example, if I am currently on https://old.user.domain.com/main.jsp , then the new link should be https://new.user.domain.com/main.jsp .
The only thing constantly changes is the user part. I currently use response.sendRedirect("/main.jsp")
to redirect on the same site, but I can't seem to figure out a way to get the part between the dots.
Solved
String user = path.substring(path.indexOf("old.") + 4, path.indexOf(".domain"));
response.sendRedirect("https://new." + user + ".domain.com/main.jsp");
请求 URI是您要查找的 URL 的一部分:
request.getRequestURI()
Solved
String user = path.substring(path.indexOf("old.") + 4, path.indexOf(".domain")); response.sendRedirect(" https://new ." + user + ".domain.com/main.jsp");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.