Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running code on server

 
Mohammad Farhat
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,
i need to call, from my applet, code to run on the server.
The code is java code which is supposed to check if an image is corrupted or not, but it needs to run on the server side
i thought about writing some batch file to run the code on the server, but i have no idea about how to call it there
any ideas?
the code i want to run on the server has this shape:
"java -jar dcm2jpg.jar file1 file2" and i want to obtain the result of running this operation, whether it crashed or not, and send it to my applet
thanks guys
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could write a servlet that does this, and then access the servlet from the applet using the URL, URLConnection or HttpUrlConnection classes.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it fair to say that, when you are designing both sides from scatch, applet <--> servlet communication is a mismatch and that it makes more sense for a applet to communicate with a web service?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't say that. WS have a definite overhead, both on the client and on the server side. Even if it is negligible performance-wise, there might be issues of developer know-how, or not wanting to deploy a SOAP engine on the server, or not wanting to deploy additional classes with the applet, or something else.

Of course, with a REST design, hitting a servlet might be considered accessing a WS, so maybe the difference is not all that big after all...
 
Mohammad Farhat
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you think i can rely on a jsp page to do the job? i'm not really familiar with servlets, besides, all i need is this simple code to be run on the server, and the response be sent to the applet...
btw, how do i call the jsp page so that it runs without displaying (is this feasible from within the applet?)
thanks guys,
Mohammad
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a servlet instead of a JSP. Seriously. With a JSP it's hard to control the formatting of the result (there will be unwanted whitespace in it); a servlet can control precisely what gets sent back.

You can access a servlet or JPS from an applet by using the java.net.URL class and its getContent method. If you need more control over the connection, have a look at the URLConnection and HttpUrlConnection classes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic