gpt4 book ai didi

java - 如何在 Jodd 操作类中获取 HttpServletRequest 对象?

转载 作者:行者123 更新时间:2023-11-30 10:59:04 24 4
gpt4 key购买 nike

我正在使用 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.htmlHttpServletResponse 注入(inject)一样,我对 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");
}
}

问题解决了。 :-)

关于java - 如何在 Jodd 操作类中获取 HttpServletRequest 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32033350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com