Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Call a stand alone application from a servlet/jsp  RSS feed

 
Assh Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am new here, need your help. I have written two stand alone java applications, trying to call the main method of the applications them from a servlet. Is there any way to call the applications from a servlet
below is my code of the servlet. Thank you so much in advance.


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do your applications do? Are they GUI programs (Swing/JavaFX)? We need more details before we can make recommendations?
 
Assh Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for your reply.. The two applications are console applications, will take few inputs from the user (number of records, type of transaction) and then gets access to the database and write the records to a file.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, no. The servlet is running on a server in a back room somewhere, in response to a user's request. There isn't going to be anybody in that back room who can enter those "few inputs" that you mention.

However if you redesigned things so that the "few inputs" were coming in to the servlet as request parameters, and so that the data was sent back to the requesting user via the servlet response, you could certainly at least reuse some of the code you wrote in the console app.

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assh Khan wrote:The two applications are console applications, will take few inputs from the user (number of records, type of transaction) and then gets access to the database and write the records to a file.


Well, if those user inputs are typed at the console and read by the application from stdin with program prompts written to stdout you might be able to create a java.lang.Process to talk to the application with those standard streams. Pretty tricky stuff.

See the javadocs for java.lang.Process and related classes.

Bill
 
Assh Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:
Assh Khan wrote:The two applications are console applications, will take few inputs from the user (number of records, type of transaction) and then gets access to the database and write the records to a file.


Well, if those user inputs are typed at the console and read by the application from stdin with program prompts written to stdout you might be able to create a java.lang.Process to talk to the application with those standard streams. Pretty tricky stuff.

See the javadocs for java.lang.Process and related classes.

Bill


Thank you so much... I am truing to find out some other ways... i have now created web based interface(JSP page) for the two applications. User will enter the parameters via text fields, radio button The user inputs will be passed to the applications as a rest API call. Here I am suffering to find the way to connect to the interface to the applications. I am getting an error when i use the @webservlet annotation maven error. Could you please let me know that either I am heading to the right technique or have to learn something else. Thank you so much in advance for you precious time.
 
Assh Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two standalone applications that will connect to the database and write the records to the files has been written. I cannot understand that how i can connect them to a web base interface that will pass basic parameter values to those applications. These parameters are such as total number of transactions, min value and max value. I want to store the values as a JSON or XML format and tun pass to the applications. Applications than save the records according to the user input in a text file and tun pass the control and saved records to the web interface and display the records. This is the whole logic, suffering to find out the connection and transfer.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it were me, I would separate the parts of the programs that perform the input from the parts that process the inputs. That way, the input can come from anywhere, and the processing parts don't care. Then you can just include and call the processing classes as part of the web app.

This is called engineering.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Bear. In Java you do not write standalone applications and expect them to be reusable components. You write classes which can be used by other applications if you want reusable components.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!