gpt4 book ai didi

java - 在 Struts Action 类中获取 Request 对象

转载 作者:行者123 更新时间:2023-12-01 13:42:43 25 4
gpt4 key购买 nike

我读到了两种不同的方法来在struts的任何操作类中获取Request对象,如下

HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get( ServletActionContext.HTTP_REQUEST);

还有

HttpServletRequest request =  ServletActionContext.getRequest();

我想知道他们两个有什么区别。看起来两者是相同的,因为 ServletActionContext 类为我们提供了请求对象。

最佳答案

ServletActionContext.getRequest() is implemented as

public static HttpServletRequest getRequest() {
return (HttpServletRequest) ActionContext.getContext().get(HTTP_REQUEST);
}

您可以直接执行或调用此方法。他们做同样的事情。

关于java - 在 Struts Action 类中获取 Request 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20585225/

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