It's not a secret anymore!
The moose likes JSP and the fly likes unable to jar file from jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "unable to jar file from jsp" Watch "unable to jar file from jsp" New topic

unable to jar file from jsp

ravi san

Joined: Jul 27, 2012
Posts: 5
I have created jar file. When I test that in any dos prompt it is working fine. Basically this jar file will submit a job in mainframe and get a results. So I wanted call thru my jsp page. I coded like below. But it is not working. Any help/suggestion will be much appricated

Greg Charles

Joined: Oct 01, 2001
Posts: 2968

Hi Ravi, welcome to JavaRanch!

Please use code tags when posting code samples here. They make code much easier to read.

I don't see the reason that's failing, but you're not giving us much to go on. Is there an exception thrown? What's the message and stack trace? It could just be you don't have a path to that jar file. Or are you expecting the output of running that jar command to get pasted into your page? You'd need to capture the output stream from process and write it to the out object for that to work.

However, you are completely misusing JSP, which is meant only for presentation. Scriptlets, i.e. Java code inside the <% ... > tags, have been obsolete for a solid decade now. Now, calling Runtime.exec even from a servlet isn't a great practice, but it's a whole lot better than calling it from a JSP. A better way of organizing this would be to call a servlet to do initial processing, put data you needed into request attributes, and then forward the request to the JSP to render.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63862

Please read this JspFaq entry, and then this article.

[Asking smart questions] [About Bear] [Books by Bear]
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

You'll also want to examine the command which you are trying to execute. Notice that it's generated by code, and code can have bugs. So don't just look at the code which generates the command, look at the actual command which was generated.
I agree. Here's the link:
subject: unable to jar file from jsp
jQuery in Action, 3rd edition