Skip to content
Advertisement

The operator && is undefined for the argument type(s) boolean, String

I am trying to check if all the conditions below return a true and then validate, but the compiler fails saying:

The operator && is undefined for the argument type(s) boolean, String

I come from JS background an not Java, so any help would be appreciated.

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);
} 

Advertisement

Answer

Change

refererURL.getPath() + "?" + refererURL.getQuery().equals(PATH)

to

(refererURL.getPath() + "?" + refererURL.getQuery()).equals(PATH)
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement