I create a web-app for accounting IT resources. There is a form on the jsp page
<form action="Searche" method="post"> ФИО: <input type="text" name = "fioSearche"/><br/> Устройство: <select name="devaiceSearche"> <option></option> <option>Ноутбук</option> <option>Монитор</option> <option>Компьютер</option> <option>Процессор</option> <option>Мат.Плата</option> <option>Оперативная память</option> <option>Жесткий диск</option> <option>Мышка</option> <option>Клавиатура</option> <option>Иное</option> </select><br/> <input type="submit" name="Searche" value="searche"/> </form> The servlet has this code to determine what we are looking for.
if(request.getParameter("fioSearch").equals("")) { query = "SELECT fio, device, id, SN, stats, date, period FROM resurces " + "WHERE device = ?"; pst = (PreparedStatement) con.prepareStatement(query); pst.setString(1,request.getParameter("deviceSearch")); } else if(request.getParameter("deviceSearch")==null) { query = "SELECT fio, device, id, SN, stats, date, period FROM resurces " + "WHERE fio = ?"; pst = (PreparedStatement) con.prepareStatement(query); pst.setString(1,request.getParameter("fioSearch")); } else if((request.getParameter("deviceSearch")!=null) && (!request.getParameter("fioSearch").equals(""))) { query = "SELECT fio, device, id, SN, stats, date, period FROM resurces " + "WHERE fio = ? AND device = ?"; pst = (PreparedStatement) con.prepareStatement(query); pst.setString(1,request.getParameter("fioSearch")); pst.setString(2,request.getParameter("deviceSearch")); } The first and second points work, the search is carried out either by full name or by device, but they don’t want to work together, as far as I understand, I don’t correctly carry out a logical check, but I can’t understand what exactly is wrong. I have already tried many options, tell me what you need to do to perform a search in both fields?

fioSearchefor an empty string, and in the lastifalready null. - MrModestsearch(withoute),device(withouta). Plus, it would be cool if you didn't send requests as a string, but worked with entity classes, so you protect yourself from typos .. - MrModest!request.getParameter("fioSearche").equals("")- for example, like this .. (note the exclamation mark at the beginning). - MrModestStringUtilsclass fromorg.apache.commons.lang3. there are such wonderful methods asisBlank()andisNotBlank()that check for null, an empty string and a string with only spaces - MrModest