Solved

How to pass objects from one JSP to another?

Posted on 2004-08-23
10
191 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 95
maven webservice projet error 6 80
error when compiling my project in eclipse luna 30 456
excpetion with multiple catch 11 122
The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 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