2

我正在使用Jodd MadvocMVC 框架。我想获取 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");
    }
}
4

1 回答 1

1

在阅读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");
    }
}

并且问题解决了。:-)

于 2015-08-16T15:30:16.953 回答