so my aim is to make a IF statement determine what the value of ‘pbutton’ and ‘value is.
I have a html page that has two lists boxes, one for PropertyID and another for Location which will look in a database for that value.
ccode and ccode1 are the list boxes from html page.
This is my code for .jsp page
String pbutton=request.getParameter("ccode");
if (pbutton = 0); {
pbutton=request.getParameter("ccode1");
value = Property;
else {
pbutton=request.getParameter("ccode");
value = ID;
}
}
However, it doesnt like it, giving me this error….
An error occurred at line: 75 in the jsp file: /Assignment/find.jsp
Type mismatch: cannot convert from String to boolean
72:
73: String pbutton=request.getParameter("ccode");
74:
75: if (pbutton = 0); {
76: pbutton=request.getParameter("ccode1");
77: value = Property;
78: else {
Help appreciated, thanks.
Here are three major mistakes. You’re assigning an
intvalue of0to aStringvariable and then checking if it istrueorfalse. The=is an assignment operator, while you actually wanted to use==which is the equality operator which returnstrueorfalse. But this is not going to work as well because you’re basically comparing aStringwith anint. Also, that semicolon doesn’t belong there, it won’t enter the statement block.To check whether the
Stringvalue equals to"0", you need this instead:This is rather trivial and basic Java and has got nothing to do with JSP. Writing Java code in JSP files instead of normal Java classes doesn’t make it a JSP problem. I’d suggest to stop with whatever you’re doing now and invest some time in learning Java properly. Start with Oracle’s own basic Java tutorial. Once having a proper grasp on Java basics, you can continue your work.