简体   繁体   English

Google App Engine JSP

[英]Google App Engine JSP

I have created a Google App Engine project, but because of some SEO concerns I want to change one of my pages from HTML (+ JQuery) to a JSP that gets rendered on the server 我已经创建了一个Google App Engine项目,但是由于一些SEO问题,我想将我的页面之一从HTML(+ JQuery)更改为在服务器上呈现的JSP

This page is the index.html file, how can I make it work as a JSP without renaming it (I don't want the user to go to index.jsp, but instead treat index.html as a JSP page) 此页面是index.html文件,如何使它作为JSP工作而不重命名(我不希望用户使用index.jsp,而是将index.html视为JSP页面)

I've tried adding this to my web.xml, but it doesn't seem to work 我尝试将其添加到我的web.xml中,但似乎不起作用

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

Any ideas on how to solve this ? 关于如何解决这个问题有什么想法吗?

If I rename the index.html to index.jsp file, everything works fine 如果我将index.html重命名为index.jsp文件,则一切正常

You can definitely do this in a Servlet filter. 您绝对可以在Servlet过滤器中执行此操作。

Set up your filter to catch requests to /index.html 设置您的过滤器以捕获对/index.html的请求

Then in the filter return index.jsp so it is seen by the client as /index.html 然后在过滤器中返回index.jsp,以便客户端将其视为/index.html

ex: 例如:

    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); 

    }

What this does is include /index.jsp in the response. 这是在响应中包含/index.jsp。 Of course, since you don't have a /index.html file then that ends up being the whole response. 当然,由于您没有/index.html文件,因此最终将成为整个响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM