#why both if conditions are executed in jstl

1 messages · Page 1 of 1 (latest)

dim dawn
#

When I need to update the user date which is not present in the database it should execute the first IF STATEMENT in JSP since the message is not null and userTable is set to null (It is supposed to work like that) . But when I try , it executs both IF STATEMENT .

Note
In controller code userTable object is set to null if the ID is not found so either userTable or message is null .

Controller code

@RequestMapping("updateUser")
    public ModelAndView updateUser(@RequestParam int id) {
        ModelAndView mav = new ModelAndView("updateUser.jsp");
        UserTable userTable = userDao.findById(id).orElse(null);
        if(userTable == null) {
            mav.addObject("message","User didn't exist");
        }else {
            userDao.deleteById(id);
            mav.addObject(userTable);
        }
        return mav;
    }```

**JSP code**

```jsp
<html>
    <head>
        <title> Welcome to .com </title>
    </head>
    <body>
        <h2> User information to be updated </h2>
                <c:if test = "message != null">
                    ${message}
                </c:if>
                <c:if test = "userTable != null">
                    ${userTable} <br> <br>
                    
                    <form action = "updateUser">
                        Enter ID <input type = "text" name = "id"> <br>
                        Enter Name <input type = "text" name = "name"> <br>
                    <input type="submit"> <br>
                    </form>
                </c:if>
    </body>```
strange waveBOT
#

<@&1004656351647117403> please have a look, thanks.

edgy linden
strange waveBOT
#

Please use this format for posting code:

```java
// Example java program
int value = 5;
System.out.println(value);
```

Which results in:

// Example java program
int value = 5;
System.out.println(value);

For syntax highlighting, you have to add the name of the language after the three backticks, like ```java. Please make sure to use exactly this format, so no space between the backticks and the language name, and a newline before the code starts. If done right, the syntax highlighting will even be applied to your text as you type, before sending.

edgy linden
#

also, its impossible that it just executes both cases

#

u must be misinterpreting whats going on

#

which means in order to help we need way more info about the entire setup

#

we need to see how exactly u call it, why u think its executing both, the content of the database, ...

#

u will need to spend like 10 mins to collect info for us

#

in ur current state its impossible to tell u what the issue is

edgy linden
dim dawn
#

Ok bruh

edgy linden
#

just post what u got when u got it

#

and then people who are available will jump on it

dim dawn
#

Full code?

#

Full controller code ?

dim dawn
#

Now there is no data in the database and am trying to update id with value 1 , it should only execute the first if statement "User didn't exist" but it also executes the next if statement which has a form inside.