Issue
I am having chicken and egg situation: i have 2 servlets and i want the di object to show through search, not by display servlet
Question:
- Is there way I can show the refID in my jsp page even if object is
empty? currently, In my code, i added default query just to fill the "dmsearch" so Jsp don't give
error
(SearchDataManagerController.searchDMData(0, 0, 0);)
. - Or any other solution so my search value should show even display servlet is loaded?
Problem: On page load, i don't necessarily want to show refId data (servlet 1). if it displays its ok BUT when i click on Search, it should display the data(servlet 2). it displays searched value in textbox but Servlet 1 loads and reset the value back.
Using "Get" in jsp
Code:
<% DataManager di = (DataManager) session.getAttribute("dmsearch"); %>
<input type="text" name="refId" id="refId" value ="<%= di.getiD() %>">
//Servlet display: 1:
DataManager dm;
String buttonClickStatus = request.getParameter("buttonClickStatus");
dm = SearchDataManagerController.searchDMData(0, 0, 0);
session.setAttribute("dmsearch", dm);
//Servlet search: 2:
dm = SearchDataManagerController.searchDMData(driverid, textid, weekid);
session.setAttribute("dmsearch", dm);
Solution
I'm not sure if this will help you but there is the Expression Language you can read about it, it's so usefull to avoid java code in jsp pages. You can try this but I'm not sure if this is what you want:
<input type="text" name="refId" id="refId" value ="${ empty di ? 1 : di.getId()}">
Answered By - Mehdi Ziat