RockyFullen
asked on
My Project Deadline - Servlet
Hi,
I am in the process of completing my first major
web-based project, or at least am due for my project
deadline of early next week.
(which I must complete, or I will be dead)
There are a few mistakes I have made, which I am sure
must be corrected to avoid major problems.
Below I have given an example similar to my program
structure. Now My issues.
myservlet is the servlet accessed by the web page.
It performs many functionalities, then prints the html output.
The way this is suppose to work is,
- user accesses servlet through web-page (with parameters passed)
- servlet creates an instance of mysubmod which loads information
from database and creates an object: Note this submod object is
suppose to be active throughout the entire session, and available
only to this user.
- output is printed based on mysubmod
- x,y (global) are used to mysubmod retain values available only for
this session.
//everything seems to work ok when I access as a single user. I am
// under the impression, however that when this interface is used
//by multiple users, there will be issues with shared global variables
// So my biggest problem is how to rework this system to handle
//session variables. Any comment to help me rework this would be
//greatly appreciated.
//Many long hours ahead of me...........
class myservlet extends httpservlet{
int x
int y
doget(){
//recieves parameters and stores
//values in x,y
printgui(x,y);
}
public void printgui(int varone, int vartwo){
someOtherPackage.submod mysubmod = new someOtherPackage.submod(x) ;
mysubmod.printHtml;
}
}
package someOtherPackage;
class submod{
int A
int B
//many global variables
public void submod(int submodrev){
A = submodrev
B = dosomething(A);
}
private void dosomething(int myvar){
do some stuff to myvar;
return myvar;
}
public String printHtml(){
//print stuff + A + B
}
}
I am in the process of completing my first major
web-based project, or at least am due for my project
deadline of early next week.
(which I must complete, or I will be dead)
There are a few mistakes I have made, which I am sure
must be corrected to avoid major problems.
Below I have given an example similar to my program
structure. Now My issues.
myservlet is the servlet accessed by the web page.
It performs many functionalities, then prints the html output.
The way this is suppose to work is,
- user accesses servlet through web-page (with parameters passed)
- servlet creates an instance of mysubmod which loads information
from database and creates an object: Note this submod object is
suppose to be active throughout the entire session, and available
only to this user.
- output is printed based on mysubmod
- x,y (global) are used to mysubmod retain values available only for
this session.
//everything seems to work ok when I access as a single user. I am
// under the impression, however that when this interface is used
//by multiple users, there will be issues with shared global variables
// So my biggest problem is how to rework this system to handle
//session variables. Any comment to help me rework this would be
//greatly appreciated.
//Many long hours ahead of me...........
class myservlet extends httpservlet{
int x
int y
doget(){
//recieves parameters and stores
//values in x,y
printgui(x,y);
}
public void printgui(int varone, int vartwo){
someOtherPackage.submod mysubmod = new someOtherPackage.submod(x)
mysubmod.printHtml;
}
}
package someOtherPackage;
class submod{
int A
int B
//many global variables
public void submod(int submodrev){
A = submodrev
B = dosomething(A);
}
private void dosomething(int myvar){
do some stuff to myvar;
return myvar;
}
public String printHtml(){
//print stuff + A + B
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What about the variables A, B which must be global to the
submod object?
These values are controlled by the servlet,
but must be maintained for the entire session. They are to
be exclusive to the session however.
How do I make these variables
retain their values throughout the session, and remain exclusive to
the session?
submod object?
These values are controlled by the servlet,
but must be maintained for the entire session. They are to
be exclusive to the session however.
How do I make these variables
retain their values throughout the session, and remain exclusive to
the session?
>>How do I make these variables
retain their values throughout the session, and remain exclusive to
the session?
By saving them in the session ;-)
retain their values throughout the session, and remain exclusive to
the session?
By saving them in the session ;-)
If they are only assigned once, you can make them the final instance variables of a bean that is then saved in the session
>> How do I make these variables retain their values throughout the session, and remain exclusive to the session?
That is exactly what we explained. Let us know if something is not clear.
That is exactly what we explained. Let us know if something is not clear.
> How do I make these variables retain their values throughout the session, and remain exclusive tothe session?
Cookies, URL Rewriting or Hidden form fields. See my link :D
Cookies, URL Rewriting or Hidden form fields. See my link :D
Ow well we just all agree on it session :D
ASKER
I understand your point on making variable x,y as session
HttpSession session = request.getSession () ;
session.setAttribute ( "X", new Integer ( x ) ) ;
session.setAttribute ( "Y", new Integer ( y ) ) ;
But variables A,B are in a completely different package, and created here
someOtherPackage.submod mysubmod = new someOtherPackage.submod(x) ;
I do not understand how to get to the variables A,B to assign them as a session variable.
HttpSession session = request.getSession () ;
session.setAttribute ( "X", new Integer ( x ) ) ;
session.setAttribute ( "Y", new Integer ( y ) ) ;
But variables A,B are in a completely different package, and created here
someOtherPackage.submod mysubmod = new someOtherPackage.submod(x)
I do not understand how to get to the variables A,B to assign them as a session variable.
>> But variables A,B are in a completely different package, and created here
>> someOtherPackage.submod mysubmod = new someOtherPackage.submod(x) ;
Where are A and B in your above example? You mean mysubmod?
You can import the packages which contain these classes, create the objects and save them in the session.
>> someOtherPackage.submod mysubmod = new someOtherPackage.submod(x)
Where are A and B in your above example? You mean mysubmod?
You can import the packages which contain these classes, create the objects and save them in the session.
>>But variables A,B are in a completely different package
That doesn't matter. The class 'SubMod' must be given get/set methods and imported
That doesn't matter. The class 'SubMod' must be given get/set methods and imported
public class submod
{
private int x ;
private int y ;
public void setX ( int x )
{
this.x = x ;
}
public int getX ()
{
return x ;
}
// same way, for Y
}
{
private int x ;
private int y ;
public void setX ( int x )
{
this.x = x ;
}
public int getX ()
{
return x ;
}
// same way, for Y
}
> That doesn't matter. The class 'SubMod' must be given get/set methods and imported
If Submod has method parameter has A & B then you can use it by passing a parameter to it.
If Submod has method parameter has A & B then you can use it by passing a parameter to it.
If you don't need to mutate it, remove the set method
And pass x, y to the constructor.
ASKER
Ok, so refering to the variables A,B in the class submod,
instance mysubmod..
If I am understanding correctly
These variables must be maintained as session variables
outside of thes mysubmod instance. The variables are
then only to be changed by the get/set methods.
my point being that these variables are not stored in the
object mysubmod, but rather in the session.
Is this correct?
I am new to bean methods as well.
instance mysubmod..
If I am understanding correctly
These variables must be maintained as session variables
outside of thes mysubmod instance. The variables are
then only to be changed by the get/set methods.
my point being that these variables are not stored in the
object mysubmod, but rather in the session.
Is this correct?
I am new to bean methods as well.
ASKER
Also, If I import it...
what does this do for me?
I was not importing....
what does this do for me?
I was not importing....
>>And pass x, y to the constructor.
It would probably be better to maintain compatibility with bean standards and use an empty ctor. You never know what you may need to do later
It would probably be better to maintain compatibility with bean standards and use an empty ctor. You never know what you may need to do later
>>
my point being that these variables are not stored in the
object mysubmod, but rather in the session.
Is this correct?
>>
Not quite. They are stored in both
my point being that these variables are not stored in the
object mysubmod, but rather in the session.
Is this correct?
>>
Not quite. They are stored in both
> Also, If I import it...
> what does this do for me?
> I was not importing....
importing is standard but it depends on you you are actually directly calling it by:
someOtherPackage.submod mysubmod = new someOtherPackage.submod(x) ;
If you import the package then you can just instantiate it like :
submod mysubmod = new submod(x);
> what does this do for me?
> I was not importing....
importing is standard but it depends on you you are actually directly calling it by:
someOtherPackage.submod mysubmod = new someOtherPackage.submod(x)
If you import the package then you can just instantiate it like :
submod mysubmod = new submod(x);
>>
Also, If I import it...
what does this do for me?
>>
It enables you to access it, create instances, etc. Otherwise you can do nothing without always using the fully-qualified name
Also, If I import it...
what does this do for me?
>>
It enables you to access it, create instances, etc. Otherwise you can do nothing without always using the fully-qualified name
and by calling the package gives you access on all the classes that are available.
>> It would probably be better to maintain compatibility with bean standards and use an empty ctor
If you do need to use it as a bean - yes. But then you need the setters to set the properties in the first place :) we were talking about: >> If you don't need to mutate it, remove the set method
If you do need to use it as a bean - yes. But then you need the setters to set the properties in the first place :) we were talking about: >> If you don't need to mutate it, remove the set method
Yes - didn't mean to contradict myself ;-)
He he ;-)
ASKER
I will try your suggestions and get back to you before Mon.
As usual, thanks for the input
I would be lost without forums.....
As usual, thanks for the input
I would be lost without forums.....
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Servlets11.html#wp64772