Solved

How to pass objects from one JSP to another?

Posted on 2004-08-23
10
188 Views
Last Modified: 2010-08-05
Dear experts,

I have a situation whereby I need to keep track of a thread and perform 2 actions:
start and stop, only after a click or selection has been done. In order to perform a start or stop
action on the next page, I would need to pass the thread object to the next page.
Is there any way that objects can be passed on to the next page?
Is "session.setAttribute("objectname", object)" workable to pass the THread to the next page?
Below are some codes tried out:
=============threadPage.jsp========================
<%
      SendRecvThread t = new SendRecvThread();
      session.setAttribute("thread",t);
      if(!t.isAlive()){
      
          %>
          <form action="startThreadAction.jsp" method="post">
          <p>Click Start to Start Thread</p>
          <p>
          <INPUT type="submit" value="Start" name="startButton" > </p>
          </p>
          </form>
          <%}//thread set alive
                else
                {
                 //thread alive
                 %>
                    <form action="stopThreadAction.jsp" method="post">
                 <p>Click Start to Stop Thread</p>
                 <p>
                 <INPUT type="submit" value="Stop" name="stopButton" ></p>
                 </p>
                 </form>
                <%
                 }//thread to be destroyed

                  %>
======================================================
0
Comment
Question by:mwcmp
10 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 125 total points
ID: 11868828
> Is "session.setAttribute("objectname", object)" workable to pass the THread to the next page?

That's the way I'd do it :-)

Sticking Threads into the session always makes me worry though...

It should work fine, but make sure the threads can reach an end, as this will be one sure-fire way of locking up a server if you get lots of hits and the threads never finish ;-)
0
 
LVL 11

Assisted Solution

by:sompol_kiatkamolchai
sompol_kiatkamolchai earned 125 total points
ID: 11868925
Please make sure that if session timeout or terminate. The thread that bind in session object will be stop. As Tim said it may lock server side resource.

You can test it by put thread in session and in the run() of thread try to loop print out something to stdoutput then close the browser and see in the stdout whether there still be printing or not.

If so, I recommend you to use listner class that trap the event session destroy and try to stop thread in that event.

best luck to you.
SomPol
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11868935
Tim,

You are so fast response. :)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11868946
This is an example of a session listener:

http://stardeveloper.com/articles/display.html?article=2001112001&page=1

Ignore the numberOfUsers malarkey, it's the sessionDestroyed thing you will need :-)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Expert Comment

by:TimYates
ID: 11868951
> You are so fast response. :)

hehehe, i'm trying to write a really complex bit of code at work, so I keep finding other things to do (like press refresh on the JSP page) ;-)

Tim
0
 

Author Comment

by:mwcmp
ID: 11877553
Hi Tim,
According to this:
It should work fine, but make sure the threads can reach an end, as this will be one sure-fire way of locking up a server if you get lots of hits and the threads never finish ;-)

I have only one thread to monitor the system. I only need to terminate it at the end of the day by only one user.
So how can I actually kill this thread at the end of the day? Does it mean the user has to keep that session active until the thread is killed? Otherwise the thread cannot be remembered?
0
 
LVL 27

Assisted Solution

by:rrz
rrz earned 125 total points
ID: 11877681
>I only need to terminate it at the end of the day by only one user.
You could use
       application.setAttribute("thread",t);
in the first page. That way it will be accessable at the end of the day.  But as Tim  said
>but make sure the threads can reach an end  
So, maybe adding a timer  would be a safeguard just in case the user forgets to stop it.        rrz
0
 
LVL 6

Assisted Solution

by:CodingExperts
CodingExperts earned 125 total points
ID: 11924474
Hi  mwcmp,
What i can suggest u is probably to have a application controller servlet thus all your request could be routed thru this servlet and on a particular selection u can start/stop the thread.  You then really don't need to pass thread objects across.

Good Luck
CodingExperts
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now