0

I am working on a jsp page where i want to redirect to pages according to following condition. only the else part is working even when i type Google in text field. P.S. I am hosting it on localhost Glassfish Server

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
<%
    String x = request.getParameter("browse");
    if (x == "Google" || x == "google") {
        response.sendRedirect("http://www.google.com");
    } else if (x == "youtube" || x == "Youtube" || x == "you tube" || x == "Music") {
        response.sendRedirect("http://www.youtube.com");
    }else {
        response.sendRedirect("http://localhost:11146/Project_Julie/" + x + ".jsp");
    }
%>
</body>
</html>
DJDaveMark
  • 2,669
  • 23
  • 35

1 Answers1

1

Use equals() method instead of == operator and your code will work.

replace if(x=="Google" || x=="google") with if("google".equals(x.toLowerCase())) apply same change in else if clause too.

Dark Knight
  • 8,218
  • 4
  • 39
  • 58