我使用的是Jodd Madvoc
MVC框架。我想获得web应用程序客户端的IP地址。我怎么能得到HttpServletRequest
对象在行动类?
@MadvocAction(value = "login")
public class LoginAction extends BaseAction {
Logger logger = LoggerFactory.getLogger(getClass());
@PetiteInject
UserService userService;
@Action
public void view() {
if (logger.isInfoEnabled())
logger.info("LoginAction.view()");
// Code for getting ip Address
forwardTo("/login.jsp");
}
}
阅读http://jodd.org/doc/madvoc/injection.html后,像HttpServletResponse
注射我做了同样的HttpServletRequest
。
@MadvocAction(value = "login")
public class LoginAction extends BaseAction {
Logger logger = LoggerFactory.getLogger(getClass());
@PetiteInject
UserService userService;
@In(scope = ScopeType.SERVLET)
protected HttpServletResponse servletResponse;
@In(scope = ScopeType.SERVLET)
protected HttpServletRequest servletRequest;
@Action
public void view() {
if (logger.isInfoEnabled())
logger.info("LoginAction.view()");
// Code for getting ip Address
forwardTo("/login.jsp");
}
}
问题就解决了。: -)