aspose file tools*
The moose likes Servlets and the fly likes Servlets and a Pre-Existing Program (Beginner) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets and a Pre-Existing Program (Beginner)" Watch "Servlets and a Pre-Existing Program (Beginner)" New topic
Author

Servlets and a Pre-Existing Program (Beginner)

Vincent Cas
Greenhorn

Joined: Mar 09, 2008
Posts: 19
I have a pre-existing java program which needs input from a webpage, specifically a drop down box.

What is the best way to pass the information from the webpage to the program? Each user selects a value from 1 to 10, puts an ID in a text box and clicks submit. I then need to collect these values in an array f[].

Also, should I create the webpage is html seperatly or use jsp?

Thanks for your time,
Vassili Vladimir
Ranch Hand

Joined: Mar 08, 2007
Posts: 1585
If i were you, i would have used a JSP/HTML with a Servlet.

Where the JSP/HTML views the data in a form element, and upon form submit, you can use the submitted data that were part of the request, and process them in the way you like in your Servlet class.

Take a look at the ServletRequest interface since you'll be using methods from this interface.

Best of luck ...


Vassili ...
SCJP 5.0, SCWCD 1.4, SCJA 1.0
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61054
    
  66

What is the best way to pass the information from the webpage to the program?
That greatly depends upon the nature of the existing program, of which you have not given us a clue.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vincent Cas
Greenhorn

Joined: Mar 09, 2008
Posts: 19
Hi,

Sorry for the huge delay in replying, I will try and explain it a bit better.

The program is a package/framework type of thing called jMetal. It simulates Multiple Objective Evolutionary Algorithms. During the run of an algorithm it calls a method evaluate(solution) for each solution.

Each time it tries to evaluate a solution, represented by a 940bit binary string, I want to use that string to produce an image file consisting of java2d objects and display it on the website.

A number of users then use the drop down box to rate the image, and enter a userID i will use to identify them. I then need to pass this information back to the java program and when all the users have responded, let the evaluation method complete.

Questions:

I have sorted out the image design in java and it writes it to a file. Is it possible to move this code to a servlet/jsp or something and have it generate the image straight to the webpage?

In a more general sense, what would be the best way to connect the information generated by the webpage with the jMetal program? The process has to occur as quickly as possible, automatically if doable.

Again sorry it took me so long to reply, any recommendations or advice would be appreciated.
Ajith Prasad
Ranch Hand

Joined: Aug 22, 2006
Posts: 66
It is bad design if you move the java code in JSP.You can write a java component and call it from JSP
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61054
    
  66

So this program is a stand-alone program running somewhere? And you want people to be able to bring some page up in a browser that sends a data element to that program?

If so, there's no need to refactor your program at all. Write a separate small web app that collects the user input, and that web app can communicate with the existing program through any of the Java messaging technologies: RMI or JMS, for example.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
best way to connect the information generated by the webpage with the jMetal program?


Unless I missed it somewhere in the discussion, you have not said how jMetal presently accepts information! There are so many possibilities!

I see that jMetal is open source - are you comfortable with doing your own modifications to the way it handles data input?

Bill
Vincent Cas
Greenhorn

Joined: Mar 09, 2008
Posts: 19
Hi,

Thanks for the recommandation of JMS or RMI, they definitly look the right thing.

As for jMetal, it comes with a number of premade 'problems' to be run witht he algorithms and a framework for writing your own. I am simply creating a problem that takes user input in the evaluation stage, not making any changes to the jMetal framework itself.

Thanks for the help.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
takes user input in the evaluation stage,


Can we please get to the point! HOW does input from the user get into jMetal

Bill
Vincent Cas
Greenhorn

Joined: Mar 09, 2008
Posts: 19
It doesn't.

The problems presented don't need or use user input, the evaluate method performs calcualtions dependent on the problem to assign values to each of the objectives of a solution.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Now I am reallllly confused - the original post said:
I have a pre-existing java program which needs input from a webpage,


Bill
Vincent Cas
Greenhorn

Joined: Mar 09, 2008
Posts: 19
Sorry, the first post wasn't clear enough, hopefully I described it a bit better in the fourth one.

Sorry for the confusion.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
The 4th post contains the words:
In a more general sense, what would be the best way to connect the information generated by the webpage with the jMetal program? The process has to occur as quickly as possible, automatically if doable.


To me this implies that jMetal can accept data/inputs somehow. How does this happen?

Bill
Vincent Cas
Greenhorn

Joined: Mar 09, 2008
Posts: 19
Ok,

jMetal doesnt accept input at the moment.

Currently jMetal provides a number of evolutionary algorithms which can be linked with pre-created problems.

When an algorithm is run the information needed for the solutions to a problem is generated randomly, no user input or input data is needed.

I am attempting to create a problem that uses user input for the evaluation of the solutions. In all the other problems the data here is generated by equations or rules using the details of each solution.

Does this clear it up?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
So you are really interested in presentation of the jMetal output with collection of user evaluations by some other process - NOT jMetal. Can you see how the statement:

connect the information generated by the webpage with the jMetal program?


sounds like something entirely different?

It appears you will be writing some sort of HTML page with a graphic visualization of the jMetal output and a Form element to collect the user's ID and evaluation.

Creating Forms in HTML and interpreting the request the form creates with a servlet is very standard stuff covered in just about any servlet tutorial, nothing new needs to be invented.

Bill
Smita Patil
Greenhorn

Joined: Apr 11, 2008
Posts: 2
Originally posted by Vassili Vladimir:
If i were you, i would have used a JSP/HTML with a Servlet.

Where the JSP/HTML views the data in a form element, and upon form submit, you can use the submitted data that were part of the request, and process them in the way you like in your Servlet class.



Best of luck ...

[ April 11, 2008: Message edited by: Smita Patil ]
Smita Patil
Greenhorn

Joined: Apr 11, 2008
Posts: 2
[QUOT
William Brogden wrote:
So you are really interested in presentation of the jMetal output with collection of user evaluations by some other process - NOT jMetal. Can you see how the statement:



sounds like something entirely different?

It appears you will be writing some sort of HTML page with a graphic visualization of the jMetal output and a Form element to collect the user's ID and evaluation.

Creating Forms in HTML and interpreting the request the form creates with a servlet is very standard stuff covered in just about any servlet tutorial, nothing new needs to be invented.

Bill
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Smita,
Why are you, weeks later, posting quots from this thread?
Do you have something to add?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
Consider Paul's rocket mass heater.
 
subject: Servlets and a Pre-Existing Program (Beginner)