Google App Engine JSP

妖精的绣舞 提交于 2021-01-29 05:04:39

问题


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

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)

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 ?

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


回答1:


You can definitely do this in a Servlet filter.

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

Then in the filter return index.jsp so it is seen by the client as /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. Of course, since you don't have a /index.html file then that ends up being the whole response.



来源:https://stackoverflow.com/questions/16037119/google-app-engine-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!