【问题标题】:JSTL fmt not workingJSTL fmt 不工作
【发布时间】:2013-10-11 15:27:09
【问题描述】:

以下是我的代码,一切正常,但 fmt 不行。

web.xml

 <jsp-config>       
        <taglib>
            <taglib-uri>/WEB-INF/tags/jstl-fmt.tld</taglib-uri>
            <taglib-location>/WEB-INF/tags/fmt.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/tags/jstl-fmt-1_0.tld</taglib-uri>
            <taglib-location>/WEB-INF/tags/fmt-1_0.tld</taglib-location>
        </taglib>
         <taglib>
            <taglib-uri>/WEB-INF/tags/jstl-fmt-1_0-rt.tld</taglib-uri>
            <taglib-location>/WEB-INF/tags/fmt-1_0-rt.tld</taglib-location>
        </taglib>
         <taglib>
            <taglib-uri>/WEB-INF/tags/jstl-c.tld</taglib-uri>
            <taglib-location>/WEB-INF/tags/c.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/WEB-INF/tags/jstl-c-1_0.tld</taglib-uri>
            <taglib-location>/WEB-INF/tags/c-1_0.tld</taglib-location>
        </taglib>
         <taglib>
            <taglib-uri>/WEB-INF/tags/jstl-c-1_0-rt.tld</taglib-uri>
            <taglib-location>/WEB-INF/tags/c-1_0-rt.tld</taglib-location>
        </taglib>
   </jsp-config>

Sample.jsp

<%@ taglib uri="/WEB-INF/tags/jstl-fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tags/jstl-c.tld" prefix="c" %>

  <html:form action="/UserAction.do">
    <fmt:message key="message.username"/>
    <c:out value="Hello" />
 </html:form>

ApplicationResource.properties

message.username=Username

标签目录

\projectName\web\WEB-INF\tags

结果

 Hello // from core
    ???message.username??? //the fmt:message.username not working

谁能帮帮我,为什么 fmt 不起作用?我尝试使用 jstl 创建 3 个或更多项目。所有的 jstl 都在工作,但只有 fmt 没有。

【问题讨论】:

  • 改用&lt;c:out value="${applicationScope.message.username}" /&gt;
  • 或试试&lt;c:out value"${initParam:message.username}"/&gt;
  • @user2511414,感谢您的回复,但我想使用 fmt 标签
  • 你使用的是什么服务器,仍然需要在 web.xml 中声明 taglib?!
  • 是的,你不应该这样做。

标签: java html jsp jstl struts1


【解决方案1】:

终于解决了。 以下代码必须插入 web.xml

<context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>com.projectName.resources.ApplicationResource</param-value>
</context-param>   

【讨论】:

  • 我正在尝试使用您的解决方案。我也有同样的问题。 com.projectName 应该是这样读还是应该是我的项目的名称?如果是我的项目,在哪里可以找到?
  • 感谢您的回复,您的 ApplicationResources 文件在您的项目中的路径是什么?另外你在哪里找到项目名称?
  • 正如您在上面看到的答案,路径是 com.projectName.resources 并且 projectName 可能不是您的项目名称。它可以是任何名称,例如:com.home.town.resources。它只是一个路径名。就我而言,我使用我的项目名称来创建资源路径。
  • 当这最终对您有用时,您的 ApplicationResources 文件的位置是什么?它是否位于 /WEB-INF/classes 的子路径中?
  • 不,它位于 src/java/com/projectName/resources
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-06
  • 2013-12-16
相关资源
最近更新 更多