Solved

How to pass objects from one JSP to another?

Posted on 2004-08-23
10
193 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat users xml 7 147
Struts tiles for layout structure along with Angular JS. 4 184
SimpleDateFormat.parse examples 19 123
countXY challenge 28 179
After hours on line I found a solution which pointed to the inherited Active Directory permissions . You have to give/allow permissions to the "Exchange trusted subsystem" for the user in the Active Directory...
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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