reset password
Author Message
p0941
Posts: 95
Posted 18:23 Mar 26, 2014 |

In Spring, can I get HttpRequest object in somewhere other than controllers? I need it in a utility method.

Thank you, 

Wen-Han

cysun
Posts: 2935
Posted 19:50 Mar 26, 2014 |

You can always pass the request as a method parameter, e.g. call MyUtils.doSomething(request) in your controller.

p0941
Posts: 95
Posted 09:44 Mar 27, 2014 |

Thank you. That method is in a utility class, and that class is not a controller. Does it still have access to HttpRequest?

 

cysun
Posts: 2935
Posted 09:53 Mar 27, 2014 |
p0941 wrote:

Thank you. That method is in a utility class, and that class is not a controller. Does it still have access to HttpRequest?

HttpRequest is an object just like any other Java object. Like I said, you can pass it to a method as a parameter (i.e. argument).