Announcement Announcement Module
Collapse
No announcement yet.
Utf-8 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Utf-8

    Hi,

    I have a hessian webservice in php that sends me the user details. There are sometimes special german characters. For example "Straße"

    These characters are not shown correctly in my java programm. In console they are like ?? two questionmarks, and in Spring Rich Client they are like this:
    http://img212.imageshack.us/img212/5717/ssspm9.gif


    Has anyone an idea how to make it work?


    In the php client that also uses this service, the characters are correct when I choose Utf-8 encoding in my browser.

    Thanks

  • #2
    after digging the internet for 2 hours, i found a solution.
    8859-1 is the default encoding of HTTP
    so to make my string readable, I did this

    new String(originalString.getBytes("8859_1"), "utf-8")

    I hope it will be useful for someone.

    Comment


    • #3
      latin 1 (= 8859-1) doesn't support the euro sign, windows-1252 (= latin 1 with euro sign) supports it.

      Anyway, what I am saying is: Run a test a string with a euro sign.

      Comment


      • #4
        Internationalization

        Hi folks,

        On a similar vein to the above poster, I am also having a problem with encodings. The below program demonstrates what I'd like to see:

        Code:
        import java.awt.Image;
        import java.io.IOException;
        
        import javax.swing.JFrame;
        import javax.swing.JTextArea;
        
        import org.springframework.core.io.ClassPathResource;
        import org.springframework.richclient.application.support.DefaultApplicationServices;
        import org.springframework.richclient.factory.ComponentFactory;
        import org.springframework.richclient.image.AwtImageResource;
        import org.springframework.richclient.image.DefaultIconSource;
        import org.springframework.richclient.image.ImageSource;
        import org.springframework.richclient.test.SpringRichTestCase;
        
        public class TestFonts extends SpringRichTestCase {
        
        	private static final byte[] bytes = new byte[] { (byte)0x2F, (byte)0x2F, (byte)0xBB, (byte)0xEF, (byte)0xBC, (byte)0xBA, (byte)0xB8, (byte)0xCA };
        
        	public static void main(String[] args) throws Exception {
        		String content = new String(bytes, "EUC-KR");
        		JTextArea ta = new JTextArea();
        		ta.setText(content);
        		JFrame frame = new JFrame("Test");
        		frame.getContentPane().add(ta);
        		frame.setBounds(300, 300, 200, 100);
        		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        		frame.setVisible(true);
        	}
        
        	protected void registerAdditionalServices(
        			DefaultApplicationServices defaultapplicationservices) {
        		try {
        			ImageSource imageSource = new ImageSource() {
        				AwtImageResource brokenImageIndicatorResource = new AwtImageResource(
        						new ClassPathResource("images/alert/error_obj.gif"));
        
        				Image brokenImageIndicator = brokenImageIndicatorResource
        						.getImage();
        
        				public Image getImage(String key) {
        					return brokenImageIndicator;
        				}
        
        				public AwtImageResource getImageResource(String key) {
        					return brokenImageIndicatorResource;
        				}
        			};
        
        			defaultapplicationservices.setImageSource(imageSource);
        			defaultapplicationservices.setIconSource(new DefaultIconSource(
        					imageSource));
        		} catch (IOException ioe) {
        			ioe.printStackTrace();
        		}
        	}
        	
        	public void testFonts() throws Exception {
        		DefaultApplicationServices das = getApplicationServices();
        		ComponentFactory cf = (ComponentFactory) das.getService(ComponentFactory.class);
        		JTextArea ta = cf.createTextArea(5, 5);
        		String content = new String(bytes, "EUC-KR");
        		ta.setText(content);
        		JFrame frame = new JFrame("Spring Test");
        		frame.getContentPane().add(ta);
        		frame.setBounds(300, 300, 200, 100);
        		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        		frame.setVisible(true);
        		Thread.sleep(10000);
        	}
        
        }
        This shows (on MY machine, anyway), the expected 4 Korean characters, both running as an app, as well as using JUnit.

        However, when I try to show them within a Form constructed within my app, I get the blocks. I have no idea how to debug this, and identify what in my configuration is causing this. Could it be a default font issue, perhaps?

        Rogan

        Comment

        Working...
        X