I am trying to setup PHP Java Bridge and I am able to invoke Java Method from PHP, But I am unable to get the request object (HttpServletRequest) in my java class. How can I get that ?
My PHP source is something like this.
<?php require_once("http://localhost:8080/PJBridge/java/Java.inc");
echo "PHP JAVA Bridge -- Calculator Test Application <br>"
$Calc= new java("test.math.Calc");
$val1 = 20;
$val2 = 10;
echo "<br> Addition of $val1 and $val2 is";
echo $Calc->add($val1,$val2);
$hello = new java("test.Hello");
echo "<br>";
echo $hello->sayHello("PHP from Java");
echo "<br>";
?>
The Java Class source is like below:-
public class Hello implements ServletRequestAware{
HttpServletRequest request;
public Hello(){
}
@Override
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public String sayHello(String name){
return "Hello " + name ;
}
}
I am getting the expected result but I need the client IP so I need to access the request object but unable to get that.
HttpServletRequestis supplied directly to your Servlet.sayHello(client_ip)or you use java_session(). If you are curious, take a look at this attempt I've made to try it out.