Sneha Goswami Sneha Goswami - 1 month ago 9
Java Question

Perform an action on JSP if redirected from a servlet

I want to perform an action on a JSP if redirected from a specific servlet only else do nothing.Is it possible?

In my JSP there are different errors defined. This JSP calls a servlet (with contentType as application/pdf) which opens in a new tab and searches for a PDF for 25 seconds and then if PDF is not found redirects to same JSP which shows the error message "File not found". I want to show the error if called from servlet only else do nothing.

JSP Code:

<%}else if(hPP!=null && hPP.get("errorcode")!=null && hPP.get("errorcode").toString().equalsIgnoreCase("Issue")){%>
<c:if test="${cameFromServlet}">
<div class="SplInputField">
<label class="FontBlod">Download fail</label>

servlet code

if (content == null) {
request.setAttribute("cameFromServlet", true);
String redirectJspUrl = request.getParameter("homeRedirect");
String strReceiptPage =
redirectJspUrl.substring(0, redirectJspUrl.lastIndexOf("/")) +

Sam Sam

Add an attribute to the request in the servlet like this

httpservletRequest.setAttribute("cameFromServlet", true)

then in your JSP check for it

<c:if test="${cameFromServlet}">