Kshitij Chandrasen

Greenhorn
+ Follow
since Oct 11, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kshitij Chandrasen

There are simple ways that I can think of -
1. Split the string with the delimiter being the sub-string that you need to search for. You would get faulty result if your sub-string is overlapping each other. For ex-
String to search in - "theyforforfortheforforin"
Sub-string to search for - "forfor"
It depends on what your requirements are.

2. You can use regular expression to find the number of matching for a regex.
Read about it here - Java Regex Documentation for Regex


I'm sure there are many more methods, explore!
12 years ago
Hi,
I'm trying to read an XML by creating a Document with the DOM parser. I make some changes there and then write it back using the Transformer class. When this class writes the Document, the <Doctype ...> tag is appearing after the initial comment, but I want it before the comment as my Flex is throwing a SAXException because of that.

Original XML -

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE .....>
<!-- The comment is here>



Output -

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- The comment is here>
<!DOCTYPE .....>



Is there any way I can manually position the DOCTYPE?
Thanks
Kshitij
13 years ago
Sai,
Yes the DOM parser doesn't do that. You will have to retrieve the "Query" tag elements as a NodeList and then iterate over them to perform search. Also, since the "queryname" and the "queryvalue" tags appear in pairs, you can actually directly retrieve these tags directly by using the getElementsByTabName(..) method and create a HashMap by mapping indices (As I said, since the items appear in pair, the index mapping would work fine).
Thanks
Kshitij
13 years ago
Megha,
I'm not sure of what you mean by "calling" a URL. However, you will need to use the java.net's URL, URLConnection and the URLHTTPConnection classes to make a server request and read the response.
13 years ago
JSP
Initializations in the constructor are generally used for non-static and non-final (obviously) class variables. Both the examples will work correctly, but as a general practice initialization of i should be done in the constructor.

Thanks,
Kshitij
13 years ago
You need to bring the the print statement for "access denied" outside the for loop, check for the value of "i" (declare i outside the scope of the loop) and print the error message accordingly.
13 years ago
Declare the counter "i" outside the scope of the loop. After the loop, check for it value, and if it is equal to 3 it means the user did not enter the correct password at the third time too.
13 years ago
Hi,
I've to write programs on calling which i'd be able to start and stop the tomcat app server. I tried this -

String[] command = new String[4];
command[0] = "cmd";
command[1] = "/C";
command[2] = "startup.bat";
command[3] = "C:\\";
String x[] = {"PATH=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.26\\bin","CATALINA_HOME=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.26","JAVA_HOME=C:\\Program Files\\Java\\jdk1.6.0_21","JRE_HOME=C:\\Program Files\\Java\\jre6"};
Process p = Runtime.getRuntime().exec(command,x);

This gives me a strange windows error saying - The system cannot find the file -Djava.util.logging.config.file="C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26\conf\logging.properties", while it actually exists.
If instead of setting the path, I give the absolute path of startup.bat in command[3], it works fine -
Process p = Runtime.getRuntime().exec("cmd /C start C:\\broadway\\bat\\startup.bat"); //I copied the startup.bat to a folder and ran it from there, it worked fine.
Please give me pointers to the right direction!
13 years ago