我正在处理一个 jsp 页面,我想根据以下条件重定向到页面。即使我在文本字段中输入 Google,也只有 else 部分在工作。PS 我在本地主机 Glassfish 服务器上托管它
<%@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>
使用equals()
方法而不是==
运算符,您的代码将起作用。
替换if(x=="Google" || x=="google")
为if("google".equals(x.toLowerCase()))
在 else if 子句中也应用相同的更改。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句