Keep your mid in your search form (the one with search button) using <input type="hidden" >
In your Demo.jsp, add a condition to see if request is come from Demo.jsp itself. (maybe check for the search button?). If request is not from search button, then do not connection to db. Instead, display a blank page with search form.
In Demo.jsp again, you have to set action of search form to itself. maybe <form action="" I'm not sure
By the way, MVC concept is highly recommended for web application development
Putting both logic, view , even connection to DB in
jsp is quite unsophisticated.