aspose file tools*
The moose likes Servlets and the fly likes servlet and StringBuffer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet and StringBuffer" Watch "servlet and StringBuffer" New topic
Author

servlet and StringBuffer

Guru Nay
Greenhorn

Joined: Dec 05, 2000
Posts: 3
Hi,
I have written a code which would parse a file by replacing a string "XXXXX" by "YYYYY" using StringBuffer class in lang package. When i use the same code in a servlet and try to execute the servlet i get the following exception,
reported this exception: java.lang.StringBuffer: method replace(IILjava/lang/String Ljava/lang/StringBuffer; not found. Please report this to the administrator of the web server.
I dont understand the reason for this. This has stopped my work and i am in a fix.. please any one of you tell me what can be
reason for this and how it can be fixed..
here is the code sample which works fine and the same method i have copied to the servelt.
import java.io.*;
import java.net.*;
import java.util.*;
public class ConvertToServlet0 {
ConvertToServlet0(){}
public static void main(String [] args) throws Exception {
System.out.println("str11");
InputStream in = new FileInputStream("testing22.html");
ConvertToServlet0 ct = new ConvertToServlet0();
char c = ' ';
String str11 = "";
while ( in.available() > 0) {
c = (char)in.read();
//System.out.println((char)c);
str11 = str11 + c;
}
//System.out.println(str11);
StringBuffer str33 = new StringBuffer(str11);
StringBuffer str22 = new StringBuffer();
System.out.println("compleetted initialization");
str22 = ct.convertASPtoServlet(str33);
System.out.println(str22.toString());
}
public StringBuffer convertASPtoServlet(StringBuffer reqfromServ) {
String tempSt = reqfromServ.toString();
System.out.println("in to the method");
int indexval = tempSt.indexOf("href");
int beginoftext = 0;
int endoftext=0;
StringBuffer st22 = new StringBuffer(tempSt);
while (indexval > 0) {

beginoftext = tempSt.indexOf('"',indexval);
beginoftext++;
endoftext = tempSt.indexOf(".text",beginoftext) ;
String textfilename = tempSt.substring(beginoftext,endoftext);
StringBuffer st1 = new StringBuffer(tempSt);
String st2 = "/servlet/"+textfilename;
tempSt = st1.replace(beginoftext, endoftext+4, st2).toString();

indexval = tempSt.indexOf("href",beginoftext);
st22 = st1;

}
indexval = tempSt.indexOf(".text");
beginoftext = 0;
endoftext=0;
while(indexval > 0) {
System.out.println("all the .text file are not replaced");
}

return st22;
}
}

Note:I am using Java SDK 2.0 v 1.2.2 in which we have StringBuffer
Using the same i have executed a program which is functioning fine
any help will be appreciated..
Thanking you in advance
Guru
manav kher
Ranch Hand

Joined: Nov 21, 2000
Posts: 98
well it appears from the error that you are using the replace method wrongly but the code you posted looks alright...is this all of it...??..can you try compiling with the stringbuffer.replace line commented out bcz thats the only place it appears you are using the replace function
manav
Guru Nay
Greenhorn

Joined: Dec 05, 2000
Posts: 3
Manav,
if i comment the replace method then the sole use of the using the replace logic is eleminated. The code which I had written compiled fine under servlets and i get error only at runtime.
my problem was, i was not able to use replace method of the StringBuffer class. If u know the reason then please let me know.
I have imlemented the replace method with the String class and it works fine.
Thanks
Guru
 
jQuery in Action, 2nd edition
 
subject: servlet and StringBuffer