force session bean expire
Hello All,
I'm working on a web app that basically presents the user with search criteria to search a database(page of checkboxes and drop boxes) that is forwarded to a jsp results page that populates a bean with the search criteria. They then can click on the result entries for more detailed info. But I need to be able to come back to the results page without the back button.
So I made the bean's scope session instead of page. Works great except when the user goes to search again with different criteria, the old bean gets used again, listing the old results.
I found that if I used session.removeValue("myBean") in the search page, it worked, but I found that if the user hits the back button that this code is not executed, leaving me with the same problem.
I guess I need some way to execute session.removeValue("myBean") between the search page and result page. Any Ideas? my searchPage is basically a form that submits to result page if that helps.
[993 byte] By [
maccarteea] at [2007-11-27 5:31:52]

# 1
Alright, I think I got it. Created the following servlet to be passed from the search page:
public class SearchPass extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res) throws java.io.IOException, ServletException {
HttpSession session = req.getSession();
session.removeAttribute("formHandler");
try {
String jsp2Call="/searchResult.jsp";
getServletConfig().getServletContext().getRequestDispatcher(jsp2Call).forward(req, res);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Any Comments?
# 2
> Works great except when the user goes to search
> again with different criteria, the old bean gets
> used again, listing the old results.
Then here is going something wrong in the code logic. How could the user get old results while the user has *submitted* new criteria? You need to overwrite the old results with the new results in the bean somehow.
# 3
Can a bean with a scope of session be overwritten? It appears creating and removing the bean gives the desired results, but I would have thought the same thing.
After submitting the form to the results page, I call
<jsp:useBean id="formHandler" class="document.FormBean" scope="session">
<jsp:setProperty name="formHandler" property="*"/>
</jsp:useBean>
After that, I use the various getter methods of the bean to add to my search query. Then, after the user selects a result entry, there is a link to go back to the results page, which uses the bean data to repopulate.