【发布时间】:2026-01-07 11:20:08
【问题描述】:
我正在尝试仅刷新起始页面(调用某些函数)说 “1.jsp” 并且一旦满足条件,它就会被重定向到另一个 jsp 页面,比如 “2.jsp”,但不知道为什么 2.jsp 也会被刷新。不仅如此,1.jsp中调用的函数也被调用了。下面是示例代码,仅供理解:
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>
** 采样过滤器**
@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");
}
}
});
}
【问题讨论】:
-
你必须写更多的信息
-
编辑了我的代码。你能看看吗
标签: java javascript jquery jsp