我正在尝试检查以下所有条件是否返回true,然后进行验证,
,但是编译器无法显示“对于参数类型boolean,字符串未定义运算符&&”。我来自JS背景和JAVA语言,因此可以提供任何帮助。
String refererHeader = httprequest.getHeader("referer");
URL refererURL = new URL(refererHeader);
String requestUrl = httprequest.getRequestURL().toString();
String refererHost = refererURL.getHost();
int refererPort = refererURL.getPort();
String serverName = httprequest.getServerName();
int serverPort = httprequest.getServerPort();
if (refererHeader == null) {
httpresponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return;
}
//Only if the refererhost , port match with server name and port and if the pathinfo matches
if(refererHeader.equals(requestUrl) &&
refererHost.equals(serverName) &&
serverPort == refererPort &&
refererURL.getPath() + "?" + refererURL.getQuery().equals(PATH)) {
chain.doFilter(request, response);
}
答案 0 :(得分:5)
更改
refererURL.getPath() + "?" + refererURL.getQuery().equals(PATH)
到
(refererURL.getPath() + "?" + refererURL.getQuery()).equals(PATH)