0

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.

2 Answers 2

3
if (pbutton = 0); {

Here are three major mistakes. You're assigning an int value of 0 to a String variable and then checking if it is true or false. The = is an assignment operator, while you actually wanted to use == which is the equality operator which returns true or false. But this is not going to work as well because you're basically comparing a String with an int. Also, that semicolon doesn't belong there, it won't enter the statement block.

To check whether the String value equals to "0", you need this instead:

if ("0".equals(pbutton)) {

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.

Sign up to request clarification or add additional context in comments.

Comments

0

== is for comparing and = is for assignment. HOWEVER when comparing strings you must use .equals in java, since == compares objects.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.