aspose file tools
The moose likes Java in General and the fly likes MessageFormat.format issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "MessageFormat.format issue " Watch "MessageFormat.format issue " New topic
Author

MessageFormat.format issue

Al Kho
Greenhorn

Joined: Jun 20, 2006
Posts: 3
Hi,

I have an application that uses MessageFormat.format. This works well in most cases except when I try to enter things like <script> or <image>. It doesn't treat these as texts but runs it!

For example, entering <image> will result in a spot for the image. If you specify the image source, then it displays the image.

Any ways to get around this?

Thanks!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

Hi,

Welcome to JavaRanch!

MessageFormat.format() can't, of course, display anything, as it just returns a String or StringBuffer. What matters is what you do with that returned object. If it looks like HTML, and you're displaying in something that knows how to display HTML, then of course you're going to get rendered HTML. Tell us what you're doing with the results from calling format().


[Jess in Action][AskingGoodQuestions]
Al Kho
Greenhorn

Joined: Jun 20, 2006
Posts: 3
The code is in a jsp:

<%= MessageFormat.format(ECMessageHelper.doubleTheApostrophy(follettText.getString("isbnNotFound")),new Object[]{request.getParameter("isbn")}) %>

where ECMessageHelper.doubleTheApostrophy(follettText.getString("isbnNotFound")) = The ISBN - "{0}" could not be found. Please check to ensure you have entered the number correctly.

and request.getParameter("isbn") = <image>

I see this on the result page with a image placeholder between the quotes.
The ISBN - "" could not be found. Please check to ensure you have entered the number correctly.
Al Kho
Greenhorn

Joined: Jun 20, 2006
Posts: 3
I guess what you're saying is that <image> will get interpreted by the browser as will <script> and any valid tags.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24061
    
  13

Originally posted by Al Kho:
I guess what you're saying is that <image> will get interpreted by the browser as will <script> and any valid tags.


Yes, so you need to convert "<" into "<" in the parameter values before sending them to format(); you could just use String.replaceAll() to do this. You might want to replace "&" and ">" characters too, for good measure.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: MessageFormat.format issue
 
Similar Threads
Question on resolving generics
css problem, the table always show below the image, not next to it
Confirmation on BrowseBean.clickSpace method
Insert JPEGs into XML
problems with form