Google App Engine JSP [英] Google App Engine JSP

查看:71
本文介绍了Google App Engine JSP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Google App Engine项目,但是由于一些SEO问题,我想将我的页面之一从HTML(+ JQuery)更改为在服务器上呈现的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

此页面是index.html文件,如何使它作为JSP工作而不重命名(我不希望用户使用index.jsp,而是将index.html视为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)

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

I've tried adding this to my web.xml, but it doesn't seem to work

<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 ?

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

If I rename the index.html to index.jsp file, everything works fine

推荐答案

您绝对可以在Servlet过滤器中做到这一点.

You can definitely do this in a Servlet filter.

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

Set up your filter to catch requests to /index.html

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

Then in the filter return index.jsp so it is seen by the client as /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文件,因此最终将成为整个响应.

What this does is include /index.jsp in the response. Of course, since you don't have a /index.html file then that ends up being the whole response.

这篇关于Google App Engine JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆