我在 Google Appengine 服务器上遇到问题,但没有找到任何解决方案,也许有人可以帮助我。
我用自己的路由器开发了一个 Polymer 应用程序,因此所有路由都在客户端完成。当我刷新页面时,请求由服务器处理,但由于没有路由匹配而无法正常工作。
为了解决这个问题,我在 web.xml 文件中设置了我希望始终提供 index.html 文件而无需处理 url,请参见下面的代码:
<!-- Always serve the index.html file if url is not defined in web.xml (It's polymer router, which will manage routing) -->
<servlet>
<servlet-name>app</servlet-name>
<jsp-file>/index.html</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
这在本地按预期工作,但是当我在生产环境中部署时出现以下错误:
java.lang.IllegalStateException: No forced path servlet for index.html
我一直在寻找解决方案,但我没有找到任何东西,如果有人有想法,我会采纳!
祝你有美好的一天!
最佳答案
这与 Polymer 无关。您需要关注 gae 错误。
java.lang.IllegalStateException: No forced path servlet for index.html
你能试试这个吗? GAE No forced path servlet for xxx.jsp
如果它不起作用,您可以创建一个 servlet 来转发请求。例如
替换
<jsp-file>/index.html</jsp-file>
使用 servlet
<servlet-class>your.package.YourServlet</servlet-class>
在 your.package.YourServlet 中覆盖 doGet
getServletContext().getRequestDispatcher("/index.html").forward(req, res);
另见 https://issuetracker.google.com/issues/35884280#comment7 , 和 https://issuetracker.google.com/issues/35884280#comment8
关于java - 在 Google Appengine 服务器上使用 Polymer 应用进行路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46977002/