freemarker无法在Google应用引擎上处理'/'的请求 [英] freemarker cannot handle request for '/' on google app engine

查看:137
本文介绍了freemarker无法在Google应用引擎上处理'/'的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让Google App Engine中的freemarker工作。我直接请求了简单的ftl模板文件,但是我希望index.ftl能够工作,否则index.html - 反之亦然。




  • 如果我请求 /index.html ,它会呈现为HTML。

  • 如果我请求 /index.ftl ,它可以很好地表现为FreeMarker模板。变量被扩展。
  • 但是,如果我请求'/',它会给出以下404消息:


    访问/索引问题。 html / index.ftl。




我的web.xml文件中包含以下内容:
blockquote>

 <?xml version =1.0encoding =utf-8?> 
xmlns:web =http://java.sun.com/xml/ns/javaee/web-app_2_5.xsdxsi:schemaLocation =http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd
version =2.5>
< welcome-file-list>
< welcome-file> index.html< / welcome-file>
< welcome-file> index.ftl< / welcome-file>
< / welcome-file-list>
< servlet>
< servlet-name> freemarker< / servlet-name>
< servlet-class> freemarker.ext.servlet.FreemarkerServlet< / servlet-class>
< init-param>
< param-name> TemplatePath< / param-name>
< param-value> file:// ftl< / param-value>
< / init-param>
<加载启动> 1< /加载启动>
< / servlet>
< servlet-mapping>
< servlet-name> freemarker< / servlet-name>
< url-pattern> *。ftl< / url-pattern>
< / servlet-mapping>
< / web-app>

我在 war / 我的Eclipse GAE应用程序的目录:




  • /index.html

  • /ftl/index.ftl

  • / WEB-INF /...



如果我切换索引的顺序.ftl和index.html条目,请求/给出以下404消息:


访问/索引问题.ftl / index.ftl。


感谢您的任何帮助。






另外一点信息是,如果我有一个< welcome-file> 条目 index.html ,它工作正常。当我添加 index.ftl 时,以任何顺序,当我得到错误。



感谢任何帮助。

解决方案

我认为这里的问题非常类似于使用 struts action as a welcome page。
引用Damien B的回答那个问题


没有(除了使用jsp重定向之外的更好的方法)。 Servlet规范
(例如Java Servlet规范2.4,
SRV.9.10欢迎文件)
状态: b
$ b

这个机制是
允许部署者为
容器指定一个
的部分URI的有序列表,用于在请求URI $ $时附加到URI
b $ b对应于
中的目录项,WAR未映射到Web组件。


由于它映射到目录项,而不是映射的Web组件,当index.ftl是欢迎文件时,/不会转发到freemarker servlet。



我建议尝试相同的用于使操作成为欢迎页面的方法。其中有一个jsp fwd给你的index.ftl。


I'm trying to get freemarker working under Google App Engine. I've gotten simple ftl template files working when requested directly however I'd like to have index.ftl work if available otherwise index.html -- or vice versa.

  • If I request /index.html, it renders fine as HTML.
  • If I request /index.ftl, it renders fine as a FreeMarker template. Variables are expanded.
  • If, however, I request '/' it gives the following 404 message:

    Problem accessing /index.html/index.ftl.

I have the following in my web.xml file:

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        version="2.5">
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.ftl</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>freemarker</servlet-name>
        <servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
        <init-param>
            <param-name>TemplatePath</param-name>
            <param-value>file://ftl</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>freemarker</servlet-name>
        <url-pattern>*.ftl</url-pattern>
    </servlet-mapping>
</web-app>

I have the following in the war/ directory of my Eclipse GAE application:

  • /index.html
  • /ftl/index.ftl
  • /WEB-INF/...

If I switch the order of the index.ftl and index.html entries, a request for / gives the following 404 message:

Problem accessing /index.ftl/index.ftl.

Thanks for any help.


One additional bit of information is that if I have one <welcome-file> entry of index.html, it works fine. When I add the index.ftl, in any order, is when I get the errors.

Thanks for any help.

解决方案

I think the problem here is pretty similar the problem of using a struts action as a welcome page. Quoting Damien B's answer from that question

There isn't ( a better way other than using a jsp redirect). Servlet specifications (Java Servlet Specification 2.4, "SRV.9.10 Welcome Files" for instance) state:

The purpose of this mechanism is to allow the deployer to specify an ordered list of partial URIs for the container to use for appending to URIs when there is a request for a URI that corresponds to a directory entry in the WAR not mapped to a Web component.

Since it is mapped to directory entry and not a mapped web component, the "/" isn't forwarding to the freemarker servlet when index.ftl is the welcome file.

I suggest trying the same approach used to make actions a welcome page. Which is have a jsp fwd to your index.ftl.

这篇关于freemarker无法在Google应用引擎上处理'/'的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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