Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to pass objects from one JSP to another?

Posted on 2004-08-23
10
Medium Priority
?
196 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 500 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 500 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 28

Assisted Solution

by:rrz
rrz earned 500 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 500 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

Industry Leaders: 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

Files go missing when using DFS (Distributed File System) Replication and how to recover them and fix it.
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

670 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