Solved

How to pass objects from one JSP to another?

Posted on 2004-08-23
10
189 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Session migration 1 103
java.util.concurrent.Callable way of creating threads 2 102
bean mapper frameworks 5 59
mask rule in struts validation.xml 5 85
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

17 Experts available now in Live!

Get 1:1 Help Now