Problem using PHP and Java
| From: | Revathi | Date: | Wed, 08 May 2002 07:40:31 +0000 |
| Subject: | Problem using PHP and Java | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-96541@lists.php.net to get a copy of this message | ||
Hi all,
I have a problem in using Java classfiles in my PHP application . I
have given some statements for debugging the class file. The Java class
works properly and returns the correct result. when I use PHP from
command line it prints out the correct result(just before return
statement) but it doesn't return anything. Do I need to make anything
else to make my PHP work ??
Here is my PHP code
<?php
$searchtext = "test";
$search = new Java("SearchPhp");
$valid = $search->validate_pattern($searchtext);
echo "Valid : ".$valid;
?>
and here is my Java code
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.table.*;
import java.util.*;
public class SearchPhp{
Vector data =null;
Vector vCheckChars=null;
String sCheckChars=new String("&|\"';:,.`~!@#$%^*(){}[]?\\/");
Vector vPattExact=null;
StringTokenizer stPattExact=null;
boolean validate=false;
boolean hasSomeValue=false;
public TableModel createTableModel() {
DefaultTableModel dtm = new DefaultTableModel();
int len = data.size();
dtm.setColumnIdentifiers(new String[] {"Path", "OutString"});
String[][] dataArray= new String[len][2];
for (int i=0;i<len;i++){
String p = (String)((FileInfo)data.elementAt(i)).getPath();
String outStr = (String)((FileInfo)data.elementAt(i)).getOutStr();
dataArray[i][0]=p;
dataArray[i][1]=outStr;
}
int size = dataArray.length;
for (int i = 0; i < size; i++){
dtm.addRow(dataArray[i]);
}
return dtm;
}
public boolean validate_pattern(String pattern){
/* validation of the search pattern to be searched */
System.out.println("Pattern : "+pattern);
String searchPattern = pattern;
if
(searchPattern==null||searchPattern.trim().equals("")||searchPattern.equals("")){
searchPattern="";
validate=true;
}
else{
vCheckChars = new Vector();
for(int i=0;i<sCheckChars.length();i++){
vCheckChars.addElement((Object)String.valueOf(sCheckChars.charAt(i)));
}
stPattExact=new StringTokenizer(searchPattern);
vPattExact=new Vector();
while(stPattExact.hasMoreTokens()){
hasSomeValue=true;
vPattExact.addElement((Object)stPattExact.nextToken());
}
if(hasSomeValue&&!validate){
String checkString = (String)vPattExact.elementAt(0);
//System.out.println(" The first element is "+checkString);
int lenCheckString=checkString.length();
for (int j=0;j<lenCheckString;j++){
if(vCheckChars.contains((Object)String.valueOf(checkString.charAt(j)))){
validate=true;
}
if(validate)
break;
}
}
}
System.out.println("Validate : "+validate);
/* Till this part of the code it works properly. */
return(validate);
}
public static void main(String args[]){
SearchPhp php = new SearchPhp();
boolean test = php.validate_pattern("test");
System.out.println("Test : "+test);
}
}
Here is the output I got by running the PHP file from the command prompt
Pattern : test
Validate : false // statement before return
statement.
X-Powered-By: PHP/4.0.5
Content-type: text/html
Valid :
Thanks,
Revathi.