gpt4 book ai didi

java - 将 httpservletrequest 传递给方法

转载 作者:行者123 更新时间:2023-12-02 07:38:52 26 4
gpt4 key购买 nike

我有一个 servlet 类,它接受 HttpServletRequest,我需要将请求传递给另一个方法。我怎样才能用另一种方法获取请求。

Servlet:

     public void doPost(final HttpServletRequest request,
final HttpServletResponse response)
XmlParser xmlParser = new XmlParser();
xmlParser.getRequest(request);

XmlParser 类:

public class XmlParser{
public void getRequest () //How can i get the request parameter from the servlet.
{
}
}

最佳答案

将其传递给构造函数:

public class XmlParser{
final private HttpServletRequest request;
public XmlParser(HttpServletRequest request)
{
this.request = request;
}
// use it in othe methods...
}

关于java - 将 httpservletrequest 传递给方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11840812/

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