java - 页面没有在jsp中重定向
问题描述
我正在处理一个 jsp 页面,我想根据以下条件重定向到页面。即使我在文本字段中键入 Google,也只有 else 部分在工作。PS 我将它托管在 localhost 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 子句中应用相同的更改。
推荐阅读
- python - 对于不同平台,segmentation.find_boundaries 的不同结果
- python - 熊猫数据框中的列顺序
- javascript - 将 Axios 承诺转换为常规 JSON 数组
- c - 来自 strtok 的分段错误
- mongodb - 在猫鼬中定义时间属性
- python - 在操作列表或字符串时,最有效的迭代方法是什么?
- r - 如何在数学上转换 ggplot 中图例上的默认标签?
- java - 使用 JAR 中的文件,同时从 jar 中运行应用程序
- amazon-s3 - s3 presinged url nginx反向代理错误 - SignatureDoesNotMatch
- android - 在已编译的应用程序中运行 Flutter builder runner