|
|
|
@ -1,6 +1,14 @@
|
|
|
|
|
package xyz.wbsite.dbtool.web.frame.utils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import xyz.wbsite.dbtool.web.frame.auth.LocalData;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* RequestUtil
|
|
|
|
@ -63,6 +71,41 @@ public class RequestUtil {
|
|
|
|
|
return request.getHeader("User-Agent");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getScheme(HttpServletRequest request) {
|
|
|
|
|
String url = request.getRequestURL().toString();
|
|
|
|
|
Pattern compile = Pattern.compile("(http|https)://(.*)/");
|
|
|
|
|
Matcher matcher = compile.matcher(url);
|
|
|
|
|
if (matcher.find()) {
|
|
|
|
|
String group = matcher.group(1);
|
|
|
|
|
return group;
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getDomain(HttpServletRequest request) {
|
|
|
|
|
String url = request.getRequestURL().toString();
|
|
|
|
|
Pattern compile = Pattern.compile("(http|https)://(.*)(:.*)?/");
|
|
|
|
|
Matcher matcher = compile.matcher(url);
|
|
|
|
|
if (matcher.find()) {
|
|
|
|
|
String group = matcher.group(2);
|
|
|
|
|
return group;
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getPort(HttpServletRequest request) {
|
|
|
|
|
String url = request.getRequestURL().toString();
|
|
|
|
|
Pattern compile = Pattern.compile("(http|https)://(.*)(:.*)?/");
|
|
|
|
|
Matcher matcher = compile.matcher(url);
|
|
|
|
|
if (matcher.find()) {
|
|
|
|
|
String group = matcher.group(3);
|
|
|
|
|
if (group == null) {
|
|
|
|
|
return Integer.parseInt(group);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 80;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取转发至错误页之前的请求URL
|
|
|
|
|
*
|
|
|
|
@ -76,4 +119,23 @@ public class RequestUtil {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setRedirect(String url) {
|
|
|
|
|
HttpServletResponse response = LocalData.getResponse();
|
|
|
|
|
try {
|
|
|
|
|
response.sendRedirect(url);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void setForward(String url) {
|
|
|
|
|
HttpServletRequest request = LocalData.getRequest();
|
|
|
|
|
HttpServletResponse response = LocalData.getResponse();
|
|
|
|
|
try {
|
|
|
|
|
request.getRequestDispatcher(url).forward(request, response);
|
|
|
|
|
} catch (ServletException | IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|