String.indexOf(String s) in GWT fails when deployed to tomcat server
I seem to be having having an issue with String.indexOf(String s)/String.lastIndexOf(开发者_如何转开发String s) in my GWT2 app when running it on a tomcat server.
The following code is in a Presenter (client side). It works perfectly when running via the GWT Eclipse plugin, but returns "" when the app is deployed to a tomcat6 server.
int start = message.indexOf("<pre>")+5;
int end = message.lastIndexOf("</pre>");
return message.substring(start, end);
If I do just message.substring(5,15) it returns correctly, but that isn't dynamic enough for what I want to do.
I do not think change of webserver should affect client side code as it is javascript which GWT code is translated into. One of the scenario which I can think of is You are populating 'pre' dyanmically and before it is set, you are trying to get its contents. Since hosted mode runs slower, this would work but may fail when code is translated into javascript and directly run into browser
If the above is true, you can try to run the 'substring' code in a timer scheduled to run a few millis later.
By the way, just in case you need Text insde HTML tags, you can use DOM.getInnerHTML
or DOM.getInnerText
From the GWT site:
You will spend most of your development time running your application in development mode, which means that you are interacting with your GWT application without it having been translated into JavaScript.
Meaning some behaviour can (will?) change when switching from hosted mode to production mode. Especially when dealing with RegEx you're likely to encounter differences. Here an example: http://code.google.com/p/google-web-toolkit/issues/detail?id=3071
It turns out that the problem isn't with String at all.
Since 'message' is:
SubmitCompleteEvent event;
message = event.getResults();
Message is dependent on the type of server: Tomcat or Jetty (via Eclipse plugin)
Tomcat doesn't use <pre>
tags in its servlet response.
My apologies for not giving that nugget of info earlier.
精彩评论