【问题标题】:Google App Engine JSP谷歌应用引擎 JSP
【发布时间】:2013-04-16 12:30:11
【问题描述】:

我创建了一个 Google App Engine 项目,但由于一些 SEO 问题,我想将我的一个页面从 HTML (+ JQuery) 更改为在服务器上呈现的 JSP

这个页面是index.html文件,我怎样才能让它作为一个JSP而不重命名它(我不希望用户去index.jsp,而是把index.html当作一个JSP页面)

我尝试将它添加到我的 web.xml,但它似乎不起作用

<servlet>
    <servlet-name>main</servlet-name>
    <jsp-file>/index.html</jsp-file>   (or index.html, same result)
 </servlet>

关于如何解决这个问题的任何想法?

如果我将 index.html 重命名为 index.jsp 文件,一切正常

【问题讨论】:

    标签: java google-app-engine jsp


    【解决方案1】:

    您绝对可以在 Servlet 过滤器中执行此操作。

    设置过滤器以捕获对 /index.html 的请求

    然后在过滤器中返回 index.jsp 以便客户端将其视为 /index.html

    例如:

        private ServletContext context;
    
        @Override public void init(FilterConfig arg0) throws ServletException {
            context = arg0.getServletContext();
    
        }
    
        @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    
            context.getRequestDispatcher("/index.jsp").include(request, response); 
    
        }
    

    它的作用是在响应中包含 /index.jsp。当然,由于您没有 /index.html 文件,因此最终会成为整个响应。

    【讨论】:

      猜你喜欢
      • 2013-05-03
      • 2019-02-12
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-12
      相关资源
      最近更新 更多