• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Writing Image from Applet

 
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a small applet in that am viewing a image using

URL url = new URL(getCodeBase(), "sample.jpg");
BufferedImage image = ImageIO.read(url);

After that am writing a new image using

URL url1 = new URL(getCodeBase(), "new.jpg");
ImageOutputStream ios = ImageIO.createImageOutputStream(url1);
ImageIO.write(image, type, ios);

But it's not working. Please assist me how to write image from Applet
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A static image served by a web server is a read-only URL. If you want to save images, then you need to send the image data to an active server-side component (like a servlet) over HTTP. That component can then save the image data on the server.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot..I will try that.. But in case if it a stanalone Applet.. Then how to save an image to the server machine..
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf,

Now it's working fine. But please assit me how to save an image now. My Application is struts and the applet class is out of WEB-INF directory, Then how can I pass the image from applet to jsp or servlet.

Please assit me
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean a stand alone application? (Applets are running inside of web browsers.) They can use any means supported by the server - HTTP upload, WebDAV, FTP, shared directory, etc. - depends on what's available.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Then how can I pass the image from applet to jsp or servlet.


The applet can make an HTTP POST to a servlet, and in that call send all data needed to reconstitute the image file.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But in my it's a struts application. Also my applet class are out of WEB-INF Folder.. So Don't know how to call the struts handler.. Please help
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there are two parts to it - the applet would contain code that makes the HTTP call, and the web app would contain code (a servlet or a Struts action) that receives the binary data sent by the image.

I suggest to start by writing an applet that makes a successful HTTP call to a servlet (or Struts action); you can worry about sending the actual image data once you have that.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am trying to access a action from the applet using

URL urlServlet = new URL(getCodeBase(), "Dummy.do");

getCodeBase() - Is returning Nullponiterexception.


Any suggestion please.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you running the applet off a server? Meaning, does the URL in the browser start with "http"? Otherwise there's no code base that could meaningfully be returned.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After placing URL urlServlet = new URL(getCodeBase(), "Dummy.do"); in the init() it's working..

Anyway to change the getcodebase() value ? Because am placing my applets in a different folder am getting that folder name too appended in the url

Thanks..
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the servlet has a different URL (which is quite likely), you can pass that URL to the applet through an applet parameter. That's a good idea anyway instead of putting any part of the servlet URL in the applet code.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats Great !!... I am doing that now

But am getting java.io.NotSerializableException: java.awt.image.BufferedImage while writing from applet




Can I try this or any other good solution ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RMI wouldn't work, but you could use the getRGB method mentioned there.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My Applet is not hitting my action. What goes wrong please help ?


 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to handle the response from the servlet, otherwise the request won't even get sent.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great Ulf.... After adding below code.. Hit goes to ApplicationController(Struts Controller) but not going to my Struts Action Handler... Any guess

Please share your thoughts


 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After removing the waitpage from struts-config it works..!!.. why it's not working if the please wait page is enabled..
 
Look ma! I'm selling my stuff!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic