JSF 页面渲染两次?

发布于 2024-12-17 13:36:56 字数 1874 浏览 0 评论 0原文

突然间,我的 JSF 2 将每个页面渲染两次(使用 Eclipse 和 Tomcat)。无论它多么简单。例如:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.prime.com.tr/ui">

<h:body>
   <h:outputText value="What's going on?"></h:outputText>
</h:body>

正在生成如下所示的结果:

发生什么事了?这是怎么回事?

如果我在其中放置更复杂的内容,它们也会在页面上显示两次。我尝试重新启动,但没有运气。那么,这是怎么回事?

编辑:

感谢大家的回答。 r0ast3d 我确实更改了 web.xml 以添加过滤器,当我删除条目时,复视消失了。但我想要过滤器...我的条目是这样的:

  <filter>
    <filter-name>dontCache</filter-name>
    <filter-class>com.company.auctions.ui.DisableCacheFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>dontCache</filter-name>
    <url-pattern>*.jsf</url-pattern>
  </filter-mapping>

这是 doFilter 方法:

public void doFilter(ServletRequest request, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    // TODO Auto-generated method stub
    // place your code here

    System.out.println("DisableCacheFilter.doFilter CALLED");

    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0); // Proxies.
    chain.doFilter(request, response);

    // pass the request along the filter chain
    chain.doFilter(request, response);
}

我做错了什么?

All of a sudden my JSF 2 is rendering every page twice (with Eclipse and Tomcat.) No matter how simple it is. For example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.prime.com.tr/ui">

<h:body>
   <h:outputText value="What's going on?"></h:outputText>
</h:body>

is generating a result that looks like this:

What's going on? What's going on?

If I put more complex stuff in there they also show up on the page twice. I tried restarting and all but no luck. So, what's going on?

Edit:

Thanks for your answer everyone. r0ast3d I did change my web.xml to add a filter, and when I removed the entries the double vision disappeared. But I want the filter... The entries I had are like this:

  <filter>
    <filter-name>dontCache</filter-name>
    <filter-class>com.company.auctions.ui.DisableCacheFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>dontCache</filter-name>
    <url-pattern>*.jsf</url-pattern>
  </filter-mapping>

This is the doFilter method:

public void doFilter(ServletRequest request, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    // TODO Auto-generated method stub
    // place your code here

    System.out.println("DisableCacheFilter.doFilter CALLED");

    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0); // Proxies.
    chain.doFilter(request, response);

    // pass the request along the filter chain
    chain.doFilter(request, response);
}

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

述情 2024-12-24 13:36:56

答案就在您的 doFilter 方法中。您正在调用 chain.doFilter(request, response) 两次。

The answer is right there in your doFilter method. You are calling chain.doFilter(request, response) twice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文