问题
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