How do i read a .properties file with tomcat 5.5/jstl 1.1.2?

Discussion in 'Java' started by Dag Sunde, Dec 19, 2006.

  1. Dag Sunde

    Dag Sunde Guest

    I have Tomcat 5.5.20 and jakarta-taglibs-standard-1.1.2

    I try to use the form: "<fmt:message key="tittel"/>" in a JSP page,
    but it shows up as: "???tittel???"

    I've copied the jstl .jar files to my WEB-INF/lib directory, and fmt.tld &
    c.tld
    to the WEB-INF directory.

    I have updated the web.xml file with the following:
    <jsp-config>
    <taglib>
    <taglib-uri>http://jakarta.apache.org/taglibs/core</taglib-uri>
    <taglib-location>/WEB-INF/c.tld</taglib-location>
    </taglib>
    <taglib>
    <taglib-uri>http://jakarta.apache.org/taglibs/fmt</taglib-uri>
    <taglib-location>/WEB-INF/fmt.tld</taglib-location>
    </taglib>
    </jsp-config>

    My .jsp file looks like this:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Insert title here</title>
    <link rel="stylesheet" type="text/css"href="styles/fotoproto.css"
    media="screen" />
    </head>
    <body>
    <fmt:setBundle basename="labels"/>
    <div style="text-align: center;">
    <h1><fmt:message key="tittel"/></h1>
    <a href="PictureResult.jsp">Ta bilde!</a>
    </div>
    </body>
    </html>

    The content of "labels.properties" id:
    tittel=Press the link below to take picture
    linklabel=Take picture...

    I tried to put my "labels.properties" file in both the
    WEB-INF/ and the WEB-INF/lib/ directory, but my

    <fmt:message key="tittel"/>

    show up as "???tittel???"

    Can anybody explain this/help me?

    TIA...

    --
    Dag.
     
    Dag Sunde, Dec 19, 2006
    #1
    1. Advertising

  2. > I tried to put my "labels.properties" file in both the
    > WEB-INF/ and the WEB-INF/lib/ directory, but my
    >

    The file must be in the container classpath. So you got WEB-INF/lib or
    WEB-INF/classes.
    You can jar it up as a resource and then put in WEB-INF/lib, or simply
    put the plain-text file in WEB-INF/classes folder. Also, try renaming
    it to labels_en.properties if your locale is english.

    -cheers,
    Manish
     
    Manish Pandit, Dec 19, 2006
    #2
    1. Advertising

  3. Dag Sunde

    Dag Sunde Guest

    Manish Pandit wrote:
    >> I tried to put my "labels.properties" file in both the
    >> WEB-INF/ and the WEB-INF/lib/ directory, but my
    >>

    > The file must be in the container classpath. So you got WEB-INF/lib or
    > WEB-INF/classes.
    > You can jar it up as a resource and then put in WEB-INF/lib, or simply
    > put the plain-text file in WEB-INF/classes folder. Also, try renaming
    > it to labels_en.properties if your locale is english.
    >


    Manish... You're a genius!

    "put the plain-text file in WEB-INF/classes"...
    (I had it in WEB-INF/lib).

    Thank You
     
    Dag Sunde, Dec 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Zeidman
    Replies:
    1
    Views:
    1,168
    Wendy S
    Aug 7, 2003
  2. Jorge Padron
    Replies:
    0
    Views:
    450
    Jorge Padron
    Aug 17, 2003
  3. Robert Mark Bram

    Custom JSTL that accepts JSTL expression

    Robert Mark Bram, Dec 15, 2004, in forum: Java
    Replies:
    0
    Views:
    1,017
    Robert Mark Bram
    Dec 15, 2004
  4. Frederic

    JSTL to access index properties

    Frederic, Feb 22, 2005, in forum: Java
    Replies:
    0
    Views:
    390
    Frederic
    Feb 22, 2005
  5. DaFoot
    Replies:
    1
    Views:
    1,775
    DaFoot
    Oct 23, 2008
Loading...

Share This Page