I want to substitute the value received from the query string to the String variable and branch conditions.
I'd like to display item 1…
Enter this URL.
http://localhost:8080/WebApplication1/programming_base1.jsp?param1=1¶m2=2¶m3=3
[programming_base1.jsp]
<%
String product1 = request.getParameter("param1");
String product2 = request.getParameter("param2");
String product3 = request.getParameter("param3");
out.print(product1);
if(product1=="1"){←I can't get through here.
out.println("Product1");
out.print(product1);
}
if(product2=="2"){
out.print("Product 2");
}
%>
As a result, the browser displays 1…
Product 1 of item 1 is also not displayed, so it doesn't seem to meet the conditions of if...
Since product1 is a string type, I thought product1=="1" would pass, but it didn't.
What is the value obtained by the query string and substituted for product1?
Please let me know.
multi-post I also ask questions on the terratail
jsp
Self-resolved.
It was resolved by using "1".equals(product1) instead of ==.
So I have to use equals for string type comparison.
© 2024 OneMinuteCode. All rights reserved.