Forums Register Login

Implementing/getting session in class without any effects in old code

+Pie Number of slices to send: Send
Dear All,

Herewith I will explain the scenario first,

We are using JSP/Servelt based web application running on Tomcat and I'm in the process of migration, struggled here.

In a servelet, 1 object being initialized that contains an pre initialized variable x = "abc".
The same class is been instantiated in more than 200 servlets.


Now the problem is the value of x has to be updated from the session.
I don't want to address all the files instead is it possible to get session in that class with out altering its methods and constructors.

Is it any easiest way to address this issue?

Kindly help me, I'm really struggling.

Regards,
Mohanasundar.n



+Pie Number of slices to send: Send
You can pass it to any POJO class, have read the below two conversations gone here already.
webpage1
webpage2
+Pie Number of slices to send: Send
 

Now the problem is the value of x has to be updated from the session.



Are you really saying that a variable used in 200 servlets changes according to a user variable contained in a session?

Given that any number of users could be using these servlets, how do you plan to keep them from mixing up the uses of that variable?

Please clarify

Bill
+Pie Number of slices to send: Send
Yes really instantiating,

Let me Explaining clearly, if any mistake forgive me.

We have an Application of 10 years old, which supports both Oracle and PostgreSQL databases.

Wherever requires db specific query/logic, we will use.



Till now we are having 2 Context for Oracle and PostgreSQL separate

For Oracle context, We have class like



For PostgreSQL context, We have same class like




classes will be used in servlets like,

[b][/b]

DBType is used in more than 200 servlet + jsp's.

Now I'm trying to join both the context,
Consider I'm keeping DBType.type in session



If I get session in DBType, I may change like this,



Hope you got my requirement.

Thanks in advance,
Mohanasundar N
+Pie Number of slices to send: Send
I'm going to assume that putting the database type in the user's session was the right decision. Although that certainly isn't obvious from what you have posted so far. For all I know it might be better to put the database type in the application scope instead of session scope.

So then that DBType class would need to have access to the user's session. If it doesn't have that now, you would have to change the DBType class so that the servlet can pass it the session. And that would mean you would have to change every servlet which uses it.

But I would really prefer to answer your first question. The one where you were told why you had to change the system in the first place. Without knowing your actual requirements, we're just left discussing incompletely-described proposed solutions to a problem which we know nothing about. So anything you get as an answer won't be very useful.
+Pie Number of slices to send: Send
I cannot go for application scope as user can choose db either oracle or PostgreSQL
+Pie Number of slices to send: Send
If all those classes need is a single string, they certainly don't need the whole session. Whats wrong with a constructor

DBType( String theType) // where the String can come from anywhere, session, cookie, hidden variable, etc.

Bill
+Pie Number of slices to send: Send
If I overload constructor, I need to address all the pages where default constructor is been used.

Is there any possibility to do this without overloading by the way of listeners or any other mecanisam to do this.

If not possible I have to address all the pages if my team lead is ready or they have to continue with two context.

+Pie Number of slices to send: Send
Are you really saying that a variable used in 200 servlets changes according each user's preferences?

Given that any number of users could be using these servlets, how do you plan to keep them from mixing up the uses of that variable?

I don't see any quick and dirty way around it. The whole set of servlets contain a bad design decision - no easy way out.

Bill
+Pie Number of slices to send: Send
Thanks bill. We are providing supports e-tendering and for few client are using oracle others postgress.
But source code are similar.
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 940 times.
Similar Threads
Boolean Question
class X that contains class X
Anonymous class Dan's Mock exam
SCJP Brainteaser (8)
Thinking in JAVA?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:20:44.