我如何在Jodd动作类中获得HttpServletRequest对象



我使用的是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");
    }
}

问题就解决了。: -)

相关内容

  • 没有找到相关文章

最新更新