So basically I using following code as a search parcel function, it has 2 button addnew and search
where both will get the value target entered in the input field, and redirected depending on which button is chose
<div>
<i class="fas fa-search"></i>
<form id="forms" method="post" action="admin_tracking.jsp">
<input name="target" type="input" placeholder = "TrackingNo..." class = "text_search"/>
</form>
</div>
<script>
function submit(value)
{
console.log(value)
if (value == "add") {
//change action of form
document.getElementById('forms').action = 'admin_tracking.jsp?status='
document.getElementById('forms').submit(); //submit
} else {
document.getElementById('forms').action = 'admin_home_result.jsp'
document.getElementById('forms').submit();
}
}
</script>
<button class="button_search" value = "add" onclick="submit(this.value)">
Add New
</button>
<button class="button_search" value = "srch" onclick="submit(this.value)">
Search
</button>
Once redirected to the search page, parcel with match trackingNo will be return and user can choose to update the status of the parcel or delete it.
When user choose to update the parcel, AdminCollectServletwill be call as followed:
href="AdminCollectServlet?target=<%=rs.getString("trackingNo")%>&from=${pageContext.request.requestURI}&query=${pageContext.request.queryString}"
to perform database update. Once completed i used the line
response.sendRedirect(request.getParameter("from") + "?" + request.getParameter("query"));
to redirect back to where the servlet is called.
But because the target was submitted in form and not as a parameter at the url, redirected page won't be able to return the search result.
I was wondering is there a way to retrieve the full form content and passed it into the response.sendredirect() like how the parameter can be pass?