Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get the remote IP address of a client in EJB project?  RSS feed

 
Samia Ouk
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello community,

I've created an Enterprise Application project with an EJB project and one web project and it runs fine. Now I would like to get the IP address of the remote client in the EJB project for some logic in my application. I tried to create a context class in the web part as the following:


And from class in EJB I tried to call the context class like:



My problem is I can't call context.java from EJB class and if I include the classe context in the EJB part I get the NullPointerException. I'v tried also to include the web project in EJB projcet properties and I get the error "Can't add cyclic references". I'm using Netbeans. How can I get the remote IP address in this case?
 
Carrow kalala
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I Don't know  well english you can try with this syntax

FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest  request = (HttpServletRequest) context.getExternalContext().getRequest();
System.out.println(request.getRemoteAddr());
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!