Passing variables from Main function to another C# class

前端 未结 4 620
轮回少年
轮回少年 2021-01-21 07:56

I\'m beating my head against the wall pretty severely with this. I have several variables inside a C# console application that I would like to re-use. However, I cannot for th

4条回答
  •  北海茫月
    2021-01-21 08:32

    I think there's a dedicated forum for struts on this site, best look there for more info.

    Quick answer: the primary way of passing values from one action to another (I think you are working with struts Action classes?) is to put the values into the request or session (so, first job for you would be to read up on those topics: HttpServletRequest and HttpSession). Struts action classes do their work in the execute() method, and that method has a parameter of type HttpServletRequest. From the request you can get a handle to the session.

    And both request and session offer methods getAttribute() and setAttribute(). So, to pass data from one action to another, set that data as a (request or session) attribute, then read out the attribute in the next action again.

提交回复
热议问题