我已经创建了一个 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文件,一切正常
最佳答案
您绝对可以在 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 文件,那么这最终将成为整个响应。
关于java - 谷歌应用程序引擎 JSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16037119/