Hi, everyone. I am working on a profanity filter that replaces profane words with asterisks. This works just great on my Apache Tomcat server, but fails with the following exception on an August, 2002 build of the Resin server. Below, I have pasted the error message, and below that, is the portion of source code that is causing the error.
Any ideas as to why this doesn't work on the Resin server? I'm new to Java. (This is in a JSP page, by the way, not a servlet.)
500 Servlet Exception
/mysite/filter_badwords.jsp:54: replace(char,char) in java.lang.String cannot be applied to (java.lang.String,java.lang.String) result[i] = result[i].replace(badwords[j], replacementString); ^ (NOTE: this carat is actually supposed to appear just below the third angle bracket on this line "[") 1 error
Resin 2.1.4 (built Fri Aug 2 14:16:52 PDT 2002)
[ July 22, 2005: Message edited by: Ben Johnson ] [ July 22, 2005: Message edited by: Ben Johnson ]
Okay, awesome. Thanks for the replies (and for the links to the API etc.)!
I gave replaceAll a shot, with some really simple code (see below), and this is what the server kicked back:
mysite/test.jsp:7: cannot resolve symbol symbol : method replaceAll (java.lang.String,java.lang.String) location: class java.lang.String output = input.replaceAll("s", "z"); ^ 1 error
Obviously, it doesn't work as expected. I am guessing that the inability to resolve a symbol is evidence of an older server that is running old Java software? Again, it works fine on Tomcat (though, you are right, that is really strange that the previous code I was using was working at all, given what you said!)
So, is this how it works... the server is running a particular version of the JDK that spawns virtual machines that do the servlet processing, and the JDK version is simply too old to support the regex methods that are contained in newer versions?
If so, is there any possible workaround? Unfortunately, I do not have access to the server on which this will be forced to run, and the IT people will assuredly refuse to do anything to facilitate this project.
Hi everyone. I think the reason "replace(String, String)" is working in Tomcat is that it's using Java 1.5. In 1.5, String has this new method:
And String implements CharSequence, so this matches.
As Ben Souther mentioned, the method:
didn't exist until 1.4, which was introduced in Feb 2002 - and evidently wasn't supported by the Aug 2002 build of Resin you are using.
Also, note that the first parameter to that method isn't interpretted as a literal String, but as a pattern from which to construct a "java.util.regex.Pattern" object and use regular expression matching... in your case, this shouldn't be an important distinction, since you are replacing "words". Oh yeah, and also not relevant because the method simply doesn't exist for you....
So, the Tomcat server seems to be running 1.5, and Resin seems to be running some version pre-1.4 (probably late 1.3).
That's odd... where'd the post go (I think it was Ben Souther's) that contained the "inefficient" function for replacing text without any fancy string manipulation packages?
And thank you for the reply, Jon. That makes perfect sense as to why Tomcat handles the call differently.
You could use org.apache.commons.lang.StringUtils
Jeffrey, how does that all work? I haven't quite figured out how to use packages like the one you described, because I don't see that it listed in the JDK 5.0 API. Is there something additional I need to download to use that class?