Strings with double quotes in messages.properties are not displayed correctly
spring-mvc
Solution
Spring resolves message codes using a `MessageSource`, which in turn uses a `MessageSourceSupport` object. If your message is the victim of the application of `MessageFormat` rules (defined here), you can just escape the double quotes using some single quotes:
The '"'name'"' field should not be null, empty, or start with an integer.
Unfortunately, `MessageFormat` doesn't state that double quotes are special characters, so this is really just a shot in the dark.
Edit:
Alright. I went and tried it. I have no problems loading double quotes as-is. My `messages.properties` has one line:
test.message = "Hello, world!"
And my test looks like this:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = TestConfiguration.class)
public class TestQuotes {
@Autowired
private MessageSource source;
@Test
public void test() {
assertEquals(
"\"Hello, world!\"",
source.getMessage("test.message", null, Locale.US));
}
}
Therefore, the only conclusion is that the `.jsp` processor consumes your double quotes - it's definitely not the message source-related objects. I don't know what object renders your `.jsp`, but you should take a closer look to see what rules it has about parsing injected values (and maybe try double-double quotes or something).
Problem
I am doing a Spring web application. In my messages.properties file, there is a one-line string as follows: ``` label.name.tooltip=The "name" field ... ``` My JSP file displays this string as follows: ``` <spring:message code="label.name.tooltip" /> ``` However, the displayed text is only "The", which means the part from "name" is cut. I dont know why this happens. Googled and the ways such as adding a backslash before double quotes are not working. Regards and thanks! Update The whole problem was caused by me using the string in the title attribute of A tag as follows: ``` a href="#" data-toggle="tooltip" title="<spring:message code="label.name.tooltip" /> ``` As Bossie hinted, the browser removes the string content starting from the double quote. Misha did quite an explanation, which helped me to understand more about how the message works. Thanks, Misha!!! I found a solution at SO that in my case, use "name" instead of double quotes. Hope this helps someone else.