I am trying to refresh just the starting page (calling some functions) say "1.jsp" and as soon as the condition is fulfilled, it is redirected to another jsp page,say "2.jsp", but not sure why the 2.jsp is also getting refreshed. Not only that, the function which was called in 1.jsp is also getting called.Below is sample code just for understanding:
1.jsp
<body>
<h1>Hello World!</h1>
<%
// Here i am trying to read some txt file which is contantly being updated. (by refreshing the page)
// when txt file is written completely, some character like "### DONE ###" will be present at its last line.
// once "### DONE ###" is found , it will be redirected to "2.jsp"
System.out.println("1");
// if "###DONE###" found
RequestDispatcher rd=request.getRequestDispatcher("2.jsp");
rd.forward(request, response);
%>
</body>
2.jsp
<body>
<h1>Hello World! PAGE 2</h1>
</body>
web.xml
<welcome-file-list>
<welcome-file>1.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>SampleFilter</filter-name>
<filter-class>com.SampleFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SampleFilter</filter-name>
<url-pattern>/2.jsp</url-pattern>
</filter-mapping>
** SampleFilter**
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, new HttpServletResponseWrapper((HttpServletResponse) response) {
public void setHeader(String name, String value) {
System.out.println(name+"-------------------------------");
if (!name.equalsIgnoreCase("Refresh")) {
System.out.println("inside");
super.setHeader("Refresh", "2");
}
}
});
}