2

I am attempting to translate the functionality of a C# API, and I have arrived at some code that I cannot find a confident solution for.

It concerns storing data in the correct web-contexted scope. For now I could have fixed the issue simply by making a HashMap, but as I do not know the extended need for the data stored at this point, I want to go the length in trying to do it right. In my attempt to find a java solution that does the same, I have come across a scope I didn't know about before, namely the Flash-scope. It seems like it is the same as HttpContext.Current.Items, but I would definitely appreciate a second opinion on this. The flashScope is something i have discovered in the playframework.

Also, HttpContext.Current.Items seems to be accessed in a static way, while java usually makes object instances of a scope class, like HttpSession.

Can I store objects in scoped dictionaries staticly, like in the C#-code below? Is the Flash scope equivalent to HttpContext.Current.Items? Can I access the Flash Scope without the Play Framework?

As always, I also very much would appreciate to know if I have made any wrong assumptions, or other misunderstandings.

Thank you :)

C# method

    public void setItem(String itemName, Object item) {

        HttpContext.Current.Items.set(itemName, item);      
    }
jumps4fun
  • 3,994
  • 10
  • 50
  • 96

2 Answers2

0

HttpServletRequest has the setattribute() method.

Minato
  • 4,383
  • 1
  • 22
  • 28
ferchoman09
  • 62
  • 1
  • 12
  • And `HttpServletRequest` is the same as `HttpContext.Current`? – jumps4fun Dec 27 '16 at 10:15
  • 1
    I'm sorry, I see this answer has two upvotes, but I am going to downvote it. It doesn't even remotely answer the question. Throwing out a single line that a class has a method, without any explanation whatsoever, is not even close to what the question asks for. – jumps4fun Dec 27 '16 at 10:18
  • Hi Bro. I only try to help you. But please, the attitud makes the difference. You asked for the equivalent, not equal. Java and C# are differents languajes. 'HttpServletRequest' it's a very used with 'HttpServletResponse'. All Java servlets have this injected variables by the server. I am attentive if you have more doubts bro. – ferchoman09 Dec 28 '16 at 12:51
  • Sorry, I did not mean for it to become personal. Thanks for trying to help. – jumps4fun Dec 28 '16 at 13:18
0

This page provides a lot of useful information on the subject: http://odetocode.com/articles/111.aspx

Among the most important lines are:

An HttpContext object will encapsulate specific details of a single HTTP request. Properties of this class include the Request object, the Response object, the Session object, and an AllErrors property which keeps an array of Exception objects accrued during the current request.

...

Current is a static property which will return the HttpContext object for the current HTTP request. You can use Current from any object in the logical thread of execution for the request

The data in Items, though accessed in a static way, are scoped to a single request. In other words, it would be logical to assume that using javas HttpServletRequest, and its methods getAttribute() and setAttribute(), is sufficient for however the translated framework is intended to be used in applications.

jumps4fun
  • 3,994
  • 10
  • 50
  • 96