• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Implementing Thread in a JSP custom tag

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am writing a JSP tag that will basically execute certain tasks and update the status in JSP page after completion of each task.

Lets take below example -

I want to verify different softwares like Tomcat/MySql/Java... before doing some operation. In my index.jsp page when I will click on button "Start Verification" at back end the custom tag will keep on verifying the softwares and display the status in same jsp page (which is already loaded)

Below is my tag support class - when its executing below highlighted line, throw error - Stream is closed.

Is there any way to create a separate thread in JSP custom tag ?

@Override
public void doTag() throws JspException
{
try
{
Thread thread = new Thread(new RecoveryLoggerThread(),"RecoveryLoggerThread");
thread.start();
}
catch (Exception e)
{
e.printStackTrace();
}

//return SKIP_BODY;
}

class RecoveryLoggerThread implements Runnable
{

@Override
public void run()
{
try
{
PageContext pageContext = (PageContext) getJspContext();
JspWriter out = pageContext.getOut();

out.println(getLogData("Tomcat", false) +"\t\t");

out.println("OK");

}
catch (Exception e)
{

e.printStackTrace();
}

}

}



 
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sanjay Mohanty wrote:I am writing a JSP tag that will basically execute certain tasks and update the status in JSP page after completion of each task.


That's not going to happen. It's just not the way that JSP or even HTTP works. The response is closed once the JSP executes and the result is sent as the response; you cannot update it later. You need a different approach.

If you want to periodically perform an operation and display results in a loaded page, you probably want to use Ajax.
 
Sanjay Mohanty
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot.

I will try Ajax option.
 
reply
    Bookmark Topic Watch Topic
  • New Topic