|
-
June 12th, 2004, 06:42 AM
#1
Applet should write JPG-Image to Webserver
hi everyone,
i have a big problem, writing a image from my applet to my apache webserver. i tried three way's of writing that file. every way was described in forums to solve this problem, but non of them worked and i don't know why. i'll give you the code of my writing-methods and describe, what happen when i test them, in order someone of you can give me a usefull tip, where the problem is.
as inputparameter i give my method a new URL referring to http://localhost/test.jpg (this is the same directory, where my applet is loaded from, so i should have reading and writing permission, havn't i? while i'm developing, my applet runs on the same pc as my webserver, just in case you're wondering about localhost) and a selfmade BufferedImage (i already testet if it is not null and shows the correct things ... all ok).
1. try:
Code:
private void writeImageToServer(URL fileURL,BufferedImage img){
try {
URLConnection urlConnection = fileURL.openConnection();
urlConnection.setDoOutput(true);
OutputStream urlout = urlConnection.getOutputStream();
BufferedOutputStream out = new BufferedOutputStream(urlout);
ImageIO.write(img,"jpg",out);
out.close(); // i also tried without this line -> same result
// additionally a question: do i need out.close()?
}
catch( IOException e ){
e.printStackTrace();
}
}
result:
test.jpg doesn't appear in the webroot. but some very strange messages in the error.log of apache:
[Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not exist: c:/programme/apache group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageOutputStreamSpi
[Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not exist: c:/programme/apache group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageReaderSpi
[Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not exist: c:/programme/apache group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageInputStreamSpi
[Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not exist: c:/programme/apache group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageWriterSpi
[Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not exist: c:/programme/apache group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageTranscoderSpi
i cannot explain this lines to myself, because my apache should have nothing todo with java. all my java is on the client side in the applet. does this mean i have to add the ImageIO package from the sdk to my jar-applet. maybe the jre, used by my iexplorer doesn't contain this files, but that's version 1.4.2_03, which contains the corresponding classfiles at javax.imageio.spi (but not the listet files in the meta-inf/services directory). i'm realy confused by this messages.
2. try:
Code:
private void writeImageToServer(URL fileURL,BufferedImage img){
try {
URLConnection urlConnection = fileURL.openConnection();
urlConnection.setDoOutput(true);
OutputStream urlout = urlConnection.getOutputStream();
BufferedOutputStream out = new BufferedOutputStream(urlout);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(img);
out.close(); // same comments as above
}
catch( IOException e ){
e.printStackTrace();
}
}
result:
nothing. no error-messages in the error.log, no exceptions in the java-console and no test.jpg in the webroot. i searched my whole harddrives for it: nothing. isn't this the way, the JPEGImageEncoder works?
3. try:
Code:
private void writeImageToServer(URL fileURL,BufferedImage img){
try {
File file = new File(fileURL.toString);
file.createNewFile();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(img);
out.close(); // same comments as above
}
catch( Exception e ){
e.printStackTrace();
}
}
result:
the SecurityManager denies this action with "access denied" while calling createNewFile(). ok, i'd have to sign my applet to get the rights to do this, or i can edit java.policy on my client, what i don't want, because i cannot do this on every client, the applet will run, when i'm finished with it. this brings me to the question: does anybody know's how to sign my applet and give it full access to the harddrive and the webserver without paying 400$ to VeriSign for a commercial CA? i want to do this by myself, without paying anything and without giving a lot of information to another company.
i would realy appreciate, if someone could give me a hint where i am wrong or how to do this correct.
thank you very much
wayne
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|