0

I want to run JADE middleware GUI from JSP, for that I created a "Dynamic Web Project" and made right click on WebContent folder and select New .. Other ..type JsP file and gave the name e.g. runJADE.jsp. Now add the following details inside runJADE.jsp

<%@ page import="jade.core.*"%>
<% try {
    String [] _args = {"-gui"};
    jade.Boot.main(_args); 
   } catch (Exception ex) {
       out.println(ex);
       ex.printStackTrace();
   }
 %>

<HTML>
<BODY>
JADE is running.
</BODY>
</HTML>

I also tried the following code in JSP page:

<%@ page import="jade.core.Profile,jade.core.ProfileImpl,jade.core.Runtime,jade.wrapper.AgentContainer %>
<% try {
        Profile profile = new ProfileImpl();
        profile.setParameter(Profile.GUI, "true");
        AgentContainer mainContainer = Runtime.instance().createMainContainer(profile);
   } catch (Exception ex) {
       out.println(ex);
       ex.printStackTrace();
   }
 %>

<HTML>
<BODY>
JADE is running.
</BODY>
</HTML>

The code gives fine result by launching the JADE but refreshing the page leads to create another GUI. Am I missing some basic step? and how to avoid this problem?

Mike Causer
  • 8,196
  • 2
  • 43
  • 63

1 Answers1

0

Your approach is deeply flawed. Every time you load your JSP, it creates another Jade container. When using Jade, you generally only want to have a single container on a single machine.

A better approach would be to start up your container when your entire application starts up. Then, when you want to trigger the Jade GUI, you should just start the RMA agent inside your Jade container, as described in this answer: https://stackoverflow.com/a/20462656/2047962


Now, let's take a step back and talk about your code. I would strongly recommend that you stop using scriptlets in your JSPs RIGHT NOW. It's a bad practice that leads to really poor designs. If you don't know the alternatives, please read "How to avoid Java code in JSP files?".

Second, why are you mixing web applications and desktop Swing UIs? Why are you opening a Swing GUI when someone accesses your web page in a browser? If you were to deploy that application, your clients would get to a page that says "JADE is running", but they wouldn't see anything. The GUI would open on the server, not the client. I can't see why you would want this functionality in a web environment.

Community
  • 1
  • 1
RustyTheBoyRobot
  • 5,891
  • 4
  • 36
  • 55