I developed jnlp applet which prints out the user input.
When I put odd number of non-english characters(eg: chinese), chrome browser prints out the last character as question mark.
input : 가
output : 가��
I checked on java console that the character is correct.
It must be bug in communication of applet to chrome browser.
IE prints out correctly.
I can resolve the issue by appending white space on applet and remove it on java script.
Anyone has any clue on the issue?
Codes are as follows.
*MainApplet.Java*
public class MainApplet extends JApplet implements JSInterface{//, Runnable {
public int stringOut(String sData) {
OutData = sData;
return 0;
}
}
*js File*
function TSToolkitRealWrapper ()
{
var OutData;
var OutDataNum;
}
var TSToolkit = new TSToolkitRealWrapper();
var attributes = { id:'TSToolkitReal',code:'com.multibrowser.test.MainApplet', width:100, height:100} ;
var parameters = {jnlp_href: getContextPath() + '/download/pkitoolkit.jnlp',
separate_jvm:true, classloader_cache:false} ;
TSToolkitRealWrapper.prototype.stringOut=function(str)
{
var nRet = TSToolkitReal.stringOut(str) ;
this.OutData= TSToolkitReal.OutData;
return nRet;
}
*HTML*
<SCRIPT language=javascript>
<!--
function StringOut(form)
{
var data = form.data.value;
var nRet = 0;
var base64Data;
nRet = TSToolkit.stringOut(data);
if (nRet > 0)
{
alert(nRet + " : " + TSToolkit.GetErrorMessage());
}
else
{
form.data1.value = TSToolkit.OutData;
}
}
-->
</SCRIPT>
*jnlp*
<?xml version="1.0" encoding="UTF-8"?>
<jnlp href="cmp.jnlp">
<information>
<title>MultiBrowser</title>
</information>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" />
<jar href="MultiBrowser.jar"/>
</resources>
<applet-desc height="200" main-class="com.multibrowser.test.MainApplet" name="MainApplet" width="200"/>
</jnlp>
I asked in several web browser forums, but there are no answers yet.
Difference between Windows and Linux is file.encoding value. Windows(ms959) and Linux(UTF-8).
I can't figure how to set the file.encoding value though.
Below didn't work. When I press 's' in java console, it still prints file.encoding=MS949.
<?xml version="1.0" encoding="UTF-8"?>
<jnlp href="pkitoolkit.jnlp">
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.6+" java-vm-args="-Dfile.encoding=UTF-8" />
<property name="file.encoding" value="UTF-8"/>
Changing the locale in windows control panel to english did work while file.encoding=UTF-8 didn't. I am still working on why this happens.
IE prints out correctly
Emm...
You give less details... anyway if you can enter chinese characters in your browser but get some rubbish on applet output means that your internet broswer supports chinese but your applet doesn't;
I presume you should watch closer to your client machine JRE encoding settings because it maybe doesn't support chinese encoding by default so maybe your applet should have some manual localization control...
A. I can advise dig deeper into applet Locale user language settings...
I suspect that the file.encoding is the problem, if you look at my own
answers below. I couldn't find how to set the encoding though
B. You can use static code like this to set property (put it at the very beginning of your applet code)
static {
System.setProperty("file.encoding", "UTF-8"); }
C.
When I put odd number of non-english characters(eg: chinese), chrome
browser prints out the last character as question mark.
and...
encoding is ms949 and the jre version is 1.7.0_17
...the conception is pretty weird :S If you have your chrome with korean letters support and it is ms949 as your client machine default encoding but at the same time you want to make your applet support utf-8 and output korean characters correctly with JS back to your ms494 encoded web page I do suspect you do face some kind of incompatible encodings %P
So first, I do recommend to make your applet web page support utf-8 encoding instead of the default ms494 because I suppose the applet and its web page cp(s) might be incompatible :S
Report if that helped
I had the same problem about 2 months ago at J2ME, I solve problem with using String.trim() method, if your text doesn't have white space at the end you could try that.
Related
I have written a JavaFX application that includes device interaction via JNA and have no issues running it as a standalone application but when embedded within a browser, and over an extended period of time, the application gradually slows down and eventually stops responding. Using JVisualVM to profiling and monitoring the application, I can see the heap growing out of control before run out of memory and the old gen memory space full.
I was able to find another question which suggests passing arguments to the VM to force more frequent garbage collection. However I have not been able to test the suggestion due to the jvm arguments not sticking.
Modifying the MyJavafxApp.html as below:
function javafxEmbed() {
dtjava.embed(
{
id: 'myApp',
url : 'demo_javafx.jnlp',
placeholder : 'javafx-app-placeholder',
width : '1100',
height : '800',
jnlp_content : 'PD94...'
},
{
jvm: "1.6.0+",
javafx : '2.2+',
jvmargs: "-XX:MaxDirectMemorySize=128M -Xmx256m"
},
{}
);
}
I am unable to see the parameters as JVM Flags or JVM arguments
Rather they are displayed in JVisualVM under the System properties tab and under UsageTracker-AppName as a single string
UsageTracker-AppName=http://localhost:8000/target/web/demo_javafx.html: java_status_events=true jnlp_href=demo_javafx.jnlp separate_jvm=true jnlp_embedded=PD94... java_arguments=-DXX:MaxDirectMemorySize=32m,-Xmx128m,-Xms32m width=1375 javafx_version=2.2+ code=dummy.class type=application/x-java-applet id=myApp javafx_applet_id=myApp height=1000 scriptable=true codebase=http://localhost:8000/target/web/
How would I start the JVM with the arguments?
Note: I shortened the jnlp_content string. I also tried to pass the jvmargs with the -D flag and without.
In your JNLP file you can pass VM parameters like this:
<j2se version="1.6+" java-vm-args="-Djnlp.fx=2.1+ -Djnlp.tk=swing" />
I also found that some of these parameters can be passed as applet-parameters:
<applet ...>
<param name="javafx_version" value="2.1+" />
<param name="scriptable" value="true" />
</applet>
Passing it to dtjava.embed() should work too.
In Deploying JavaFX Applications is described how:
var app = new dtjava.App(
'ssh.jnlp',
{
id: 'SSH',
width: 100,
height: 25,
placeholder: 'SSH_application_container',
params: {
config: 'ssh_application.conf',
}
}
);
var platform = new dtjava.Platform({
javafx: "2.1+",
jvmargs: "-Dapp.property= ? -Xmx1024m"
});
dtjava.launch(app, platform);
The syntax you used should work too. Maybe it is just a question about which parameter to put where (as in app-parameter or vm-parameter). It also seems that the same parameter can have different names when passed in by different ways (eg. javafx: "2.1+", <param name="javafx_version" value="2.1+" /> -Djnlp.fx=2.1+), but maybe they also do different things.
I changed a file in Orbeon Forms, and the next time I load the page, I get an error message saying Invalid byte 2 of a 3-byte UTF-8 sequence. How can I solve this problem?
This happens when Orbeon Forms reads an XML file and expects it to use the UTF-8 encoding, but somehow the file isn't properly encoded in UTF-8. To solve this, make sure that:
You have an XML declaration at the beginning of the file saying the file is in UTF-8:
<?xml version="1.0" encoding="UTF-8" ?>
Your editor is XML-aware, so it can parse the XML declaration and consequently use the UTF-8 encoding. If your editor isn't XML aware, and you don't want to use another editor, look for an option or preference allowing you to specify that the editor must use UTF-8.
A three byte UTF-8 sequence looks like:
1110xxxx 10xxxxxx 10xxxxxx
Your error message may mean that the first byte of the three is incorrectly flagging the start of a three byte sequence or else that the second byte is malformed.
As #avernet says, you need to make sure that all elements in your system are producing and expecting UTF-8.
When you start your program, use the following Java command line argument:
-Dfile.encoding=UTF-8
For example,
java -Dfile.encoding=UTF-8 -jar foo.jar
I got the same problem in Eclipse, I just tried by changing the file type.
Right click on file -> Resource -> Text file encoding (UTF-8)
This solution worked for me.
Thanks.
I am using Eclipse and I also had to change the Text file encoding in:
->Windows->Preferences->Workspace
Then it worked fine.
Thanks
You might need to configure your Tomcat with the following parameter:
-Dfile.encoding=UTF-8
Had same problem.
Problem > I'm getting X509 certificate values (multiple encoding source) to generate a PDF report.
The PDF is generated throught a webservice that waits for an UTF-8 xml request and I've to reencode the values before marshalling.
Solution >
http://fabioangelini.wordpress.com/2011/08/04/converting-java-string-fromto-utf-8/
Using this class:
public class StringHelper {
// convert from UTF-8 -> internal Java String format
public static String convertFromUTF8(String s) {
String out = null;
try {
out = new String(s.getBytes("ISO-8859-1"), "UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
return null;
}
return out;
}
// convert from internal Java String format -> UTF-8
public static String convertToUTF8(String s) {
String out = null;
try {
out = new String(s.getBytes("UTF-8"), "ISO-8859-1");
} catch (java.io.UnsupportedEncodingException e) {
return null;
}
return out;
}
}
Usage:
//getSummaryAttMap() returns a HashMap
String value = (String) getSummaryAttMap().get(key);
if(value != null)
value = StringHelper.convertToUTF8(value);
else
value = "";
I'll provide a special coding answer. When you check the xml file and there's nothing wrong, and you're using Java and running Tomcat Server. Your source code may neglect specify the encoding yourself, and thus JVM uses default encoding when read in xml contents as string or something else that repesents string, which in turn refer to Tomcat's default encoding. If encoding of xml and Tomcat are inconsistent, it might also report same error message.
The switching of the encoding for the input might help:
XMLEventReader eventReader =
inputFactory.createXMLEventReader(in,
"utf-8"
//"windows-1251"
);
I love Resharper, but sometimes it gives incorrect warnings, probably because the built-in annotations for BCL types are wrong. For instance, in this code:
private static string GetDescription(T value)
{
Type type = typeof(T);
string name = Enum.GetName(type, value);
if (name != null)
{
...
It gives me a warning on the if statement: "Expression is always true". But Enum.GetName can return null:
string name = Enum.GetName(typeof(DayOfWeek), (DayOfWeek)42); // null
I assume this is because there is a [NotNull] annotation for Enum.GetName. Is there a way to fix that so I don't get the warning?
Note: I'm using Resharper 5.1; perhaps that issue is fixed in version 6, but I'm not willing to upgrade right now.
OK, I got it. The built-in annotations are defined in XML files in the Resharper installation directory (C:\Program Files (x86)\JetBrains\ReSharper\v5.1\Bin\ExternalAnnotations\ on my machine). The solution is to edit the appropriate file to remove or fix the incorrect annotations.
In the case of Enum.GetName, the file to change is mscorlib\mscorlib.[version].Contracts.xml. I just commented this annotation:
<member name="M:System.Enum.GetName(System.Type,System.Object)">
<attribute ctor="M:JetBrains.Annotations.NotNullAttribute.#ctor" />
</member>
And restarted Visual Studio, and now the warning is gone :)
Just an update to Thomas's answer, they seem to have moved things around in the last couple of years.
For Resharper 8.2.3, the above file now resides in:
C:\Users\YOUR_USER_NAME\AppData\Local\JetBrains\ReSharper\vAny\packages\ReSharper.ExternalAnnotations.8.2.3001\ReSharper\vAny\annotations\.NETFramework\mscorlib\...
so, if you're trying to do that, you can search that path (or one up, for non mscorlib files).
I have a weird problem with deferred binding. I have defined the following module:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Defines the usercategory property and its provider function. -->
<module>
<define-property name="usercategory" values="c00,c01,c02" />
<collapse-property name="usercategory" values="*" />
<property-provider name="usercategory"><![CDATA[
// Look for the usercategory cookie
var cs = document.cookie.split(';');
for (var i = 0; i < cs.length; i++) {
var name = cs[i].substr(0, cs[i].indexOf("="));
var value = cs[i].substr(cs[i].indexOf("=") + 1);
name = name.replace(/^\s+|\s+$/g,"");
if (name == "usercategory") {
return unescape(value);
}
}
return "c00";
]]></property-provider>
</module>
which sets the property usercategory by looking at the value of a cookie named usercategory.
I use this property application.gwt.xml to defer binding of some classes, for example:
<inherits name="com.example.UserCategory"/>
<replace-with class="com.example.client.ui.menu.MainMenuView01">
<when-type-is class="com.example.client.ui.menu.MainMenuView"/>
<when-property-is name="usercategory" value="c01"/>
</replace-with>
This works like a charm when I'm in development mode (i.e. when running my app from within Eclipse). However, if I compile the app and deploy it (in Jetty, but I don't this this is the problem), then deferred binding does not seem to work, and the expected classes are not loaded. I've checked and the cookie is set up properly with the correct value c01, but class com.example.client.ui.menu.MainMenuView01 is not loaded.
Am I missing something? Am I doing something wrong?
Thank you in advance!
There are two possibilities. You are doing something wrong, or there is another bug in GWT compiler. I've tried to implement a case like your and it was working when compiled without any problems. So most likely there can be some error on your side. So what i recommend to do is to compile app with -style PRETTY and see how it was compiled. find function named com_example_client_ui_menu_MainMenuView(), and see if it able to create MainMenuView01, try to debug it and etc. Anyway this kind of stuff should be working without any problems.
Also try to debug your property provider (and use vars $doc and $wnd in property provider instead of window)
Another possible case is that the cookie might be not readable from JS
I figured out what the problem was, and I'm writing it here in case others might be interested.
The module that I defined (see code in my question) defines a property whose value is taken from a cookie, that is generated after the user logs in the application.
Originally I had a GWT Place for the login, and when the user successfully authenticated the application moved to another Place. In this case when the user enter the application, and the GWT Javascript is downloaded to the browser, the cookie is not set yet (because the user has not performed login yet). Therefore the deferred binding does not work, and the expected classes (like com.example.client.ui.menu.MainMenuView01) are not loaded.
I have no idea why this works correctly when run in development mode. Anyway. the solution that I implemented is to move the login phase outside of the GWT application, and when the login is successful, I add the cookie and the redirect the user to the actual GWT application.
help me please i'm having the following issue:
I'm trying to read a XML file that looks like this:
<service />
<parameters>
<parametro nombreParametro="payment" valorParametro="<?xml version="1.0" encoding="utf-16"?>" tipoParametro="string" />
</parameters>
The xml file is well formed, but as you can see, i have an < < and > > characters as attribute on some elements and the problem is that when i tried to read the file like this:
xmlDoc.LoadXml(stringWithXmlFileContent);
It gives me the following error:
Additional information: '<', hexadecimal value 0x3C, is not a valid character or attribute. Line XX, position XX.
What should i do to avoid this error, i don't want to make a Replace cause i'm building a generic method.
Thanks in advance.
I can't reproduce this, assuming that what you posted was only a portion of the XML file. (If it was the whole file, then the problem is it doesn't have a single root element, as Rubens said in his answer). Here's a short but complete program showing the same attribute value not having a problem:
using System;
using System.Xml;
public class Test
{
public static void Main(String[] args)
{
string xml = "<element attr=\"<?xml version="1.0""
+ " encoding="utf-16"?>\" />";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
Console.WriteLine(doc.OuterXml);
}
}
Can you edit your question to include a similar program which does show the problem?
Seems your XML file isnt well-formed, as you must have a single root element.
Can you tell us how are your building this file?