File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes error in properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "error in properties file" Watch "error in properties file" New topic
Author

error in properties file

krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
Struts-config.xml:

<message-resources parameter="MessageResources" />
<message-resources key="test" parameter="TestMessageResources" null="false" />

TestMessageResources.properties is in /WEB-INF/classes.

TestMessageResources.properties:

form.firstName=First Name.
form.lastName=Last Name.
form.emailID=Email ID.
form.password=Password.

JSP files:
<bean:message bundle="test" key="form.firstName" />: <html:text property="firstName"/><br>
<bean:message bundle="test" key="form.lastName" />: <html:text property="lastName"/><br>
<bean:message bundle="test" key="form.emailID" /> : <html:text property="email"/><br>
<bean:message bundle="test" key="form.password" /> : <html:text property="password"/><br>

This is what i get

???en_US.form.firstName???:
???en_US.form.lastName???:
???en_US.form.emailID??? :
???en_US.form.password??? :

When I include the keys in MessageResources, the default file,and change my jsp, it works fine. what is the problem.


have a great day,
krishna prasad
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
All I can tell you, Krisp, is that you must be making some small error somewhere. When I try this exact same scenario in a test application, it works fine for me. Are you misspelling the name of the properties file? does it really exist in WEB-INF/classes? Are you remembering to restart the server after making changes in the message bundle files or the struts-config.xml file?

The only other thing I'd suggest is to check the integrity of your Struts installation. Make sure all artifacts are from the same Struts download (including jar files, xml files, etc.), and that the DTD referenced in the struts-config.xml file matches the one found in the sample config file in the struts-blank.war file.
[ March 22, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
I checked everything. It's fine. I started my server and typed in the address. the following error mesage appeared.

exception

org.apache.jasper.JasperException: java.lang.IllegalArgumentException: Malformed \uxxxx encoding.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:565)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


root cause

java.lang.IllegalArgumentException: Malformed \uxxxx encoding.
java.util.Properties.loadConvert(Unknown Source)
java.util.Properties.load(Unknown Source)
org.apache.struts.util.PropertyMessageResources.loadLocale(PropertyMessageResources.java:250)
org.apache.struts.util.PropertyMessageResources.getMessage(PropertyMessageResources.java:177)
org.apache.struts.util.MessageResources.getMessage(MessageResources.java:296)
org.apache.struts.taglib.TagUtils.message(TagUtils.java:953)
org.apache.struts.taglib.bean.MessageTag.doStartTag(MessageTag.java:221)
org.apache.jsp.login_jsp._jspx_meth_bean_005fmessage_005f0(login_jsp.java:165)
org.apache.jsp.login_jsp._jspx_meth_html_005fform_005f0(login_jsp.java:106)
org.apache.jsp.login_jsp._jspService(login_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:390)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)



when i refresh the the page, the jsp page was displayed, but without proper messages in that particular properties file.

[B]???en_US.form.firstName???: text area
???en_US.form.lastName???: text area
???en_US.form.emailID??? : text area
???en_US.form.password???: text area
signup button.[/B]

this behaviour happens over and over again. the first time, I start the server, the error message appears, and when i refresh the page the jsp page was displayed with messages in propeties file missing. why does this behaviour occur? start the server, error, refresh, jsp page displayed without message in properties file.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The messages in the stack trace indicate that your properties file has invalid characters in it. My recommendation would be to create a new file and re-type the messages into it (Don't cut and paste). Make sure whatever text editor you're using is set to output plain text and not unicode. Then delete the old file and copy the new one into the WEB-INF/classes directory.
[ March 27, 2007: Message edited by: Merrill Higginson ]
krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
but, why is this anomalous behaviour - after every restart of the server, the first request produces an error and the subsequent refreshing produces the desired page, with key messages in properties file missing.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Struts uses "lazy initialization" to initialize the message bundles. The first time you try to access a message, it gives you the error message that it wasn't able to initialize the bundle. The second and subsequent times, it gives you the results of an uninitialized bundle: Messages are not found.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error in properties file