Struts -> bean:message -> "Missing key"

Pessoal,

Fui convencido (tarde demais) a estudar o Struts.

Baixei um strutsSample.war completo e executei sobre struts 1.0 com sucesso.

Tentei criar o meu primeiro projeto sobre struts 1.1 e ocorreram alguns problemas.

Estou obtendo a seguinte exceção tentando executar o “Login” Struts.

javax.servlet.ServletException: Missing message for key "login.title"

Aparentemente o struts não tá conseguindo achar meu ApplicationResources.properties (este é o arquivo de properties que contem login.title). Inicialmente eu coloquei o <init-param>application no meu web.xml, não funcionou, tentei então colocar no meu struts-config.xml:

      &lt;message-resources 
        factory=&quot;org.apache.struts.util.PropertyMessageResourcesFactory&quot; 
        key=&quot;org.apache.struts.action.MESSAGE&quot; 
        null=&quot;true&quot; 
        parameter=&quot;com.oreilly.ApplicationResources&quot; /&gt; 

Meu arquivo ApplicationResources.properties está no arquivo war dentro da estrutura:

&lt;my-web-context&gt;/WEB-INF/classes/com/oreilly

Ele tem uma chave “login.title” configurada corretamente.

Por favor, não me recomendem ver o struts-example.war, pois eu já o fiz :evil: . Funcionou legal.

Thanks

manda ai o ApplicationResources.properties pra nois da uma olhada :slight_smile:

Pega aí:

login.title=Login Struts Sample
error.userName.required=u00C9 necessu00E1rio um nome de usuu00E1rio
error.login.authenticate=username/password invu00E1lido
errors.footer=&lt;/ul&gt;&lt;hr&gt;
errors.header=&lt;h3&gt;&lt;font color=&quot;red&quot;&gt;Page 
Validation&lt;/font&gt;&lt;/h3&gt;Corrija o&#40;s&#41; seguinte&#40;s&#41; erro&#40;s&#41; 
antes de continuar&#58;&lt;ul&gt;
applicationResources=Cannot load application resources bundle

tente somente

      &lt;message-resources 
        parameter=&quot;com.oreilly.ApplicationResources&quot; /&gt; 

parece certinho,
tu tem o output do tomcat quando inicializa o site??
nrmalmente ele mostra algumas mensagens de inicialização do struts, falando dos resources carregados e …

Aí vai galera:

Fiz o que o nakayatomo propôs.

Segue os logs.

Inicialização do Tomcat:

01/07/2003 18&#58;04&#58;39 org.apache.commons.modeler.Registry loadRegistry
INFO&#58; Loading registry information
01/07/2003 18&#58;04&#58;39 org.apache.commons.modeler.Registry getRegistry
INFO&#58; Creating new Registry instance
01/07/2003 18&#58;04&#58;40 org.apache.commons.modeler.Registry getServer
INFO&#58; Creating MBeanServer
01/07/2003 18&#58;04&#58;44 org.apache.coyote.http11.Http11Protocol init
INFO&#58; Initializing Coyote HTTP/1.1 on port 8080
Starting service Tomcat-Standalone
Apache Tomcat/4.1.18-LE-jdk14
01/07/2003 18&#58;05&#58;11 org.apache.struts.util.PropertyMessageResources &lt;init&gt;
INFO&#58; Initializing, config='org.apache.struts.util.LocalStrings', returnNull=tru
e
01/07/2003 18&#58;05&#58;11 org.apache.struts.util.PropertyMessageResources &lt;init&gt;
INFO&#58; Initializing, config='org.apache.struts.action.ActionResources', returnNul
l=true
01/07/2003 18&#58;05&#58;12 org.apache.struts.util.PropertyMessageResources &lt;init&gt;
INFO&#58; Initializing, config='com.oreilly.ApplicationResources', returnNull=true
01/07/2003 18&#58;05&#58;12 org.apache.coyote.http11.Http11Protocol start
INFO&#58; Starting Coyote HTTP/1.1 on port 8080
01/07/2003 18&#58;05&#58;13 org.apache.jk.common.ChannelSocket init
INFO&#58; JK2&#58; ajp13 listening on /0.0.0.0&#58;8009
01/07/2003 18&#58;05&#58;13 org.apache.jk.server.JkMain start
INFO&#58; Jk running ID=0 time=30/300  config=F&#58;USRjboss-3.0.6_tomcat-4.1.18	omca
t-4.1.xconfjk2.properties

Arquivo de log do Tomcat após 1 requisição a http://localhost:8080/strutsSample:

2003-07-01 18&#58;05&#58;02 WebappLoader&#91;/webdav&#93;&#58; Deploying class repositories to work directory F&#58;USRjboss-3.0.6_tomcat-4.1.18	omcat-4.1.xworkStandalonelocalhostwebdav
2003-07-01 18&#58;05&#58;03 StandardManager&#91;/webdav&#93;&#58; Seeding random number generator class java.security.SecureRandom
2003-07-01 18&#58;05&#58;03 StandardManager&#91;/webdav&#93;&#58; Seeding of random number generator has been completed
2003-07-01 18&#58;05&#58;03 StandardWrapper&#91;/webdav&#58;default&#93;&#58; Loading container servlet default
2003-07-01 18&#58;05&#58;03 StandardWrapper&#91;/webdav&#58;invoker&#93;&#58; Loading container servlet invoker
2003-07-01 18&#58;05&#58;05 WebappLoader&#91;/tomcat-docs&#93;&#58; Deploying class repositories to work directory F&#58;USRjboss-3.0.6_tomcat-4.1.18	omcat-4.1.xworkStandalonelocalhost	omcat-docs
2003-07-01 18&#58;05&#58;05 StandardManager&#91;/tomcat-docs&#93;&#58; Seeding random number generator class java.security.SecureRandom
2003-07-01 18&#58;05&#58;05 StandardManager&#91;/tomcat-docs&#93;&#58; Seeding of random number generator has been completed
2003-07-01 18&#58;05&#58;05 StandardWrapper&#91;/tomcat-docs&#58;default&#93;&#58; Loading container servlet default
2003-07-01 18&#58;05&#58;05 StandardWrapper&#91;/tomcat-docs&#58;invoker&#93;&#58; Loading container servlet invoker
2003-07-01 18&#58;05&#58;05 WebappLoader&#91;/manager&#93;&#58; Deploying class repositories to work directory F&#58;USRjboss-3.0.6_tomcat-4.1.18	omcat-4.1.xworkStandalonelocalhostmanager
2003-07-01 18&#58;05&#58;05 ContextConfig&#91;/manager&#93;&#58; Configured an authenticator for method BASIC
2003-07-01 18&#58;05&#58;05 StandardManager&#91;/manager&#93;&#58; Seeding random number generator class java.security.SecureRandom
2003-07-01 18&#58;05&#58;05 StandardManager&#91;/manager&#93;&#58; Seeding of random number generator has been completed
2003-07-01 18&#58;05&#58;05 StandardWrapper&#91;/manager&#58;default&#93;&#58; Loading container servlet default
2003-07-01 18&#58;05&#58;05 StandardWrapper&#91;/manager&#58;invoker&#93;&#58; Loading container servlet invoker
2003-07-01 18&#58;05&#58;05 WebappLoader&#91;&#93;&#58; Deploying class repositories to work directory F&#58;USRjboss-3.0.6_tomcat-4.1.18	omcat-4.1.xworkStandalonelocalhost\_
2003-07-01 18&#58;05&#58;06 StandardManager&#91;&#93;&#58; Seeding random number generator class java.security.SecureRandom
2003-07-01 18&#58;05&#58;06 StandardManager&#91;&#93;&#58; Seeding of random number generator has been completed
2003-07-01 18&#58;05&#58;06 StandardWrapper&#91;&#58;default&#93;&#58; Loading container servlet default
2003-07-01 18&#58;05&#58;06 StandardWrapper&#91;&#58;invoker&#93;&#58; Loading container servlet invoker
2003-07-01 18&#58;05&#58;06 HostConfig&#91;localhost&#93;&#58; Expanding web application archive strutsSample.war
2003-07-01 18&#58;05&#58;06 StandardHost&#91;localhost&#93;&#58; Installing web application at context path /strutsSample from URL file&#58;F&#58;/USR/jboss-3.0.6_tomcat-4.1.18/tomcat-4.1.x/webapps/strutsSample
2003-07-01 18&#58;05&#58;06 WebappLoader&#91;/strutsSample&#93;&#58; Deploying class repositories to work directory F&#58;USRjboss-3.0.6_tomcat-4.1.18	omcat-4.1.xworkStandalonelocalhoststrutsSample
2003-07-01 18&#58;05&#58;06 WebappLoader&#91;/strutsSample&#93;&#58; Deploy class files /WEB-INF/classes to F&#58;USRjboss-3.0.6_tomcat-4.1.18	omcat-4.1.xwebappsstrutsSampleWEB-INFclasses
2003-07-01 18&#58;05&#58;06 WebappLoader&#91;/strutsSample&#93;&#58; Deploy JAR /WEB-INF/lib/struts.jar to F&#58;USRjboss-3.0.6_tomcat-4.1.18	omcat-4.1.xwebappsstrutsSampleWEB-INFlibstruts.jar
2003-07-01 18&#58;05&#58;09 StandardManager&#91;/strutsSample&#93;&#58; Seeding random number generator class java.security.SecureRandom
2003-07-01 18&#58;05&#58;09 StandardManager&#91;/strutsSample&#93;&#58; Seeding of random number generator has been completed
2003-07-01 18&#58;05&#58;10 StandardWrapper&#91;/strutsSample&#58;default&#93;&#58; Loading container servlet default
2003-07-01 18&#58;05&#58;12 StandardWrapper&#91;/strutsSample&#58;invoker&#93;&#58; Loading container servlet invoker
2003-07-01 18&#58;06&#58;42 StandardWrapperValve&#91;jsp&#93;&#58; Servlet.service&#40;&#41; for servlet jsp threw exception
org.apache.jasper.JasperException&#58; Missing message for key &quot;login.title&quot;
	at org.apache.jasper.servlet.JspServletWrapper.service&#40;JspServletWrapper.java&#58;248&#41;
	at org.apache.jasper.servlet.JspServlet.serviceJspFile&#40;JspServlet.java&#58;295&#41;
	at org.apache.jasper.servlet.JspServlet.service&#40;JspServlet.java&#58;241&#41;
	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;853&#41;
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;247&#41;
	at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationFilterChain.java&#58;193&#41;
	at org.apache.catalina.core.StandardWrapperValve.invoke&#40;StandardWrapperValve.java&#58;260&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;643&#41;
	at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;480&#41;
	at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
	at org.apache.catalina.core.StandardContextValve.invoke&#40;StandardContextValve.java&#58;191&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;643&#41;
	at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;480&#41;
	at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
	at org.apache.catalina.core.StandardContext.invoke&#40;StandardContext.java&#58;2415&#41;
	at org.apache.catalina.core.StandardHostValve.invoke&#40;StandardHostValve.java&#58;180&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;643&#41;
	at org.apache.catalina.valves.ErrorDispatcherValve.invoke&#40;ErrorDispatcherValve.java&#58;170&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;641&#41;
	at org.apache.catalina.valves.ErrorReportValve.invoke&#40;ErrorReportValve.java&#58;172&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;641&#41;
	at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;480&#41;
	at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
	at org.apache.catalina.core.StandardEngineValve.invoke&#40;StandardEngineValve.java&#58;174&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;643&#41;
	at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;480&#41;
	at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
	at org.apache.coyote.tomcat4.CoyoteAdapter.service&#40;CoyoteAdapter.java&#58;223&#41;
	at org.apache.coyote.http11.Http11Processor.process&#40;Http11Processor.java&#58;432&#41;
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection&#40;Http11Protocol.java&#58;386&#41;
	at org.apache.tomcat.util.net.TcpWorkerThread.runIt&#40;PoolTcpEndpoint.java&#58;534&#41;
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadPool.java&#58;530&#41;
	at java.lang.Thread.run&#40;Thread.java&#58;536&#41;
----- Root Cause -----
javax.servlet.ServletException&#58; Missing message for key &quot;login.title&quot;
	at org.apache.jasper.runtime.PageContextImpl.handlePageException&#40;PageContextImpl.java&#58;530&#41;
	at org.apache.jsp.Login_jsp._jspService&#40;Login_jsp.java&#58;95&#41;
	at org.apache.jasper.runtime.HttpJspBase.service&#40;HttpJspBase.java&#58;137&#41;
	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;853&#41;
	at org.apache.jasper.servlet.JspServletWrapper.service&#40;JspServletWrapper.java&#58;204&#41;
	at org.apache.jasper.servlet.JspServlet.serviceJspFile&#40;JspServlet.java&#58;295&#41;
	at org.apache.jasper.servlet.JspServlet.service&#40;JspServlet.java&#58;241&#41;
	at javax.servlet.http.HttpServlet.service&#40;HttpServlet.java&#58;853&#41;
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter&#40;ApplicationFilterChain.java&#58;247&#41;
	at org.apache.catalina.core.ApplicationFilterChain.doFilter&#40;ApplicationFilterChain.java&#58;193&#41;
	at org.apache.catalina.core.StandardWrapperValve.invoke&#40;StandardWrapperValve.java&#58;260&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;643&#41;
	at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;480&#41;
	at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
	at org.apache.catalina.core.StandardContextValve.invoke&#40;StandardContextValve.java&#58;191&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;643&#41;
	at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;480&#41;
	at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
	at org.apache.catalina.core.StandardContext.invoke&#40;StandardContext.java&#58;2415&#41;
	at org.apache.catalina.core.StandardHostValve.invoke&#40;StandardHostValve.java&#58;180&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;643&#41;
	at org.apache.catalina.valves.ErrorDispatcherValve.invoke&#40;ErrorDispatcherValve.java&#58;170&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;641&#41;
	at org.apache.catalina.valves.ErrorReportValve.invoke&#40;ErrorReportValve.java&#58;172&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;641&#41;
	at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;480&#41;
	at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
	at org.apache.catalina.core.StandardEngineValve.invoke&#40;StandardEngineValve.java&#58;174&#41;
	at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext&#40;StandardPipeline.java&#58;643&#41;
	at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;480&#41;
	at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;995&#41;
	at org.apache.coyote.tomcat4.CoyoteAdapter.service&#40;CoyoteAdapter.java&#58;223&#41;
	at org.apache.coyote.http11.Http11Processor.process&#40;Http11Processor.java&#58;432&#41;
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection&#40;Http11Protocol.java&#58;386&#41;
	at org.apache.tomcat.util.net.TcpWorkerThread.runIt&#40;PoolTcpEndpoint.java&#58;534&#41;
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadPool.java&#58;530&#41;
	at java.lang.Thread.run&#40;Thread.java&#58;536&#41;

Na tela do Tomcat após a requisição:

...
01/07/2003 18&#58;15&#58;43 org.apache.struts.util.PropertyMessageResources &lt;init&gt;
INFO&#58; Initializing, config='org.apache.struts.taglib.bean.LocalStrings', returnN
ull=true

Forma que estou usando o bean no JSP:

...
&lt;%@ taglib uri=&quot;/WEB-INF/struts-bean.tld&quot; prefix=&quot;bean&quot; %&gt;
...
&lt;title&gt;&lt;bean&#58;message key=&quot;login.title&quot; /&gt;&lt;/title&gt;
...

Eu tenho que especificar um Locale em algum lugar ? Onde ?

Thanks

provavelmente você esta utilizando windows e esta com algum problema de case no nome do arquivo, tent renomear ele para alguma outra coisa e renomear de volta :slight_smile:

Valeu galera, tá funcionando :smiley:

Eu não entendi bem o que aconteceu, então refiz o módulo de “Login” do exemplo Struts a partir do zero e agora tudo funciona.

Devo ter tropeçado na versão anterior. :roll:

Obrigado pela ajuda.