PDA

View Full Version : Getting client IP addresse


onsongoinc
Jul 12th, 2007, 11:18 AM
I have developed a web application using spring and would like to record the client IP address to keep track of people using the application. Any ideas on how I could do that? I would like to do it inside the controller class. Thanks

EP_Guy
Jul 12th, 2007, 03:36 PM
request.getRemoteAddr()

Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR.
Returns:
a String containing the IP address of the client that sent the request

onsongoinc
Jul 12th, 2007, 04:37 PM
request.getRemoteAddr(); is giving me an error. Here is part of my code

------------------
public ModelAndView onSubmit(HttpServletRequest request, Object command, BindException errors) throws ServletException, IOException {
GoSlimAnnotation slimAnnotation = (GoSlimAnnotation) command;
String addr = request.getRemoteAddr();
------------------

This is the error I am getting

-----------

javax.servlet.ServletException: successView isn't set
at org.springframework.web.servlet.mvc.SimpleFormCont roller.onSubmit(SimpleFormController.java:416)
at org.springframework.web.servlet.mvc.SimpleFormCont roller.onSubmit(SimpleFormController.java:380)
at org.springframework.web.servlet.mvc.SimpleFormCont roller.processFormSubmission(SimpleFormController. java:267)
at org.springframework.web.servlet.mvc.AbstractFormCo ntroller.handleRequestInternal(AbstractFormControl ler.java:250)
at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:48)
at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:819)
at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:754)
at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:399)
at org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:364)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:154)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:92)
at com.caucho.server.dispatch.ServletFilterChain.doFi lter(ServletFilterChain.java:103)
at com.caucho.server.webapp.WebAppFilterChain.doFilte r(WebAppFilterChain.java:167)
at com.caucho.server.dispatch.ServletInvocation.servi ce(ServletInvocation.java:226)
at com.caucho.server.http.HttpRequest.handleRequest(H ttpRequest.java:263)
at com.caucho.server.port.TcpConnection.run(TcpConnec tion.java:477)
at com.caucho.util.ThreadPool$Item.runTasks(ThreadPoo l.java:591)
at com.caucho.util.ThreadPool$Item.run(ThreadPool.jav a:513)
at java.lang.Thread.run(Thread.java:637)

cwilkes
Jul 12th, 2007, 06:12 PM
request.getRemoteAddr(); is giving me an error. Here is part of my code

------------------
public ModelAndView onSubmit(HttpServletRequest request, Object command, BindException errors) throws ServletException, IOException {
GoSlimAnnotation slimAnnotation = (GoSlimAnnotation) command;
String addr = request.getRemoteAddr();
------------------

This is the error I am getting

-----------

javax.servlet.ServletException: successView isn't set

I'm going out on a limb here, but I think this means your successView isn't set. You must set it in your XML / java code for your particular controller.

onsongoinc
Jul 12th, 2007, 07:18 PM
I am setting the successView in the controller class. If I set it in the XML, it does not include the object I am adding. (i.e mav.addObject("goSlimCombinedList", lr);) Here is a sample of the code

----------
ModelAndView mav = new ModelAndView(getSuccessView());
mav.addObject("goSlimCombinedList", lr);
return mav;
---------

Is there a way of redirecting the setSuccessView from the XML file to my controller class?

jonnio
Jul 12th, 2007, 10:04 PM
Why not hoist an apache server instance in front. Then you can log what you like.