Using Toolkit.getDefaultToolkit().getImage() within JSP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Scharlemann

    Using Toolkit.getDefaultToolkit().getImage() within JSP

    I am attempting to upload a picture to a webserver and create a
    thumbnail from the picture uploaded. The problem comes in when I
    attempt to create an Image object from the File object (which is the
    location of the uploaded picture)...I get the following error:

    java.lang.NoCla ssDefFoundError
    at java.lang.Class .forName0(Nativ e Method)
    at java.lang.Class .forName(Class. java:130)
    at java.awt.Toolki t$2.run(Toolkit .java:712)
    at java.security.A ccessController .doPrivileged(N ative Method)
    at java.awt.Toolki t.getDefaultToo lkit(Toolkit.ja va:703)
    at _admin._addpict ure__jsp._jspSe rvice(/www/mcmanis.scharle mann.com/admin/addpicture.jsp: 89)
    at com.caucho.jsp. JavaPage.servic e(JavaPage.java :74)
    at com.caucho.jsp. Page.subservice (Page.java:485)
    at com.caucho.serv er.http.FilterC hainPage.doFilt er(FilterChainP age.java:176)
    at com.caucho.serv er.http.Invocat ion.service(Inv ocation.java:27 8)
    at com.caucho.serv er.http.Servlet Server.serviceT op(ServletServe r.java:847)
    at com.caucho.serv er.http.HttpReq uest.handleRequ est(HttpRequest .java:213)
    at com.caucho.serv er.http.HttpReq uest.handleConn ection(HttpRequ est.java:158)
    at com.caucho.serv er.TcpConnectio n.run(TcpConnec tion.java:140)
    at java.lang.Threa d.run(Thread.ja va:536)


    Basically here is what happens. I use a multipart/form-data html form
    within my html page to upload the picture to the server. I have no
    problem doing this. The picture is saved in a temporary location. I
    then attempt to create a thumbnail from the picture with the code from
    here: http://www.geocities.com/marcoschmid...thumbnail.html

    The problem is...whether in a JavaBean...or directly in the JSP
    page...the line where I try to create the Image with the Toolkit
    throws the NoClassDefFound Error.


    Line 87 in addpicture.jsp is:
    Image image = Toolkit.getDefa ultToolkit().ge tImage(
    file.getCanonic alPath());

    where file is the object pointing to the temporary location of the
    uploaded picture. If anyone has any idea how to fix/get arround this
    problem I would appreciate any help. Thanks
  • Neomorph

    #2
    Re: Using Toolkit.getDefa ultToolkit().ge tImage() within JSP

    On 30 Aug 2003 20:58:00 -0700, greg@dreamatlan tic.com (Greg Scharlemann)
    two-finger typed:
    [color=blue]
    >I am attempting to upload a picture to a webserver and create a
    >thumbnail from the picture uploaded. The problem comes in when I
    >attempt to create an Image object from the File object (which is the
    >location of the uploaded picture)...I get the following error:
    >
    >java.lang.NoCl assDefFoundErro r
    > at java.lang.Class .forName0(Nativ e Method)
    > at java.lang.Class .forName(Class. java:130)
    > at java.awt.Toolki t$2.run(Toolkit .java:712)
    > at java.security.A ccessController .doPrivileged(N ative Method)
    > at java.awt.Toolki t.getDefaultToo lkit(Toolkit.ja va:703)
    > at _admin._addpict ure__jsp._jspSe rvice(/www/mcmanis.scharle mann.com/admin/addpicture.jsp: 89)
    > at com.caucho.jsp. JavaPage.servic e(JavaPage.java :74)
    > at com.caucho.jsp. Page.subservice (Page.java:485)
    > at com.caucho.serv er.http.FilterC hainPage.doFilt er(FilterChainP age.java:176)
    > at com.caucho.serv er.http.Invocat ion.service(Inv ocation.java:27 8)
    > at com.caucho.serv er.http.Servlet Server.serviceT op(ServletServe r.java:847)
    > at com.caucho.serv er.http.HttpReq uest.handleRequ est(HttpRequest .java:213)
    > at com.caucho.serv er.http.HttpReq uest.handleConn ection(HttpRequ est.java:158)
    > at com.caucho.serv er.TcpConnectio n.run(TcpConnec tion.java:140)
    > at java.lang.Threa d.run(Thread.ja va:536)
    >
    >
    >Basically here is what happens. I use a multipart/form-data html form
    >within my html page to upload the picture to the server. I have no
    >problem doing this. The picture is saved in a temporary location. I
    >then attempt to create a thumbnail from the picture with the code from
    >here: http://www.geocities.com/marcoschmid...thumbnail.html
    >
    >The problem is...whether in a JavaBean...or directly in the JSP
    >page...the line where I try to create the Image with the Toolkit
    >throws the NoClassDefFound Error.
    >
    >
    >Line 87 in addpicture.jsp is:
    > Image image = Toolkit.getDefa ultToolkit().ge tImage(
    > file.getCanonic alPath());
    >
    >where file is the object pointing to the temporary location of the
    >uploaded picture. If anyone has any idea how to fix/get arround this
    >problem I would appreciate any help. Thanks[/color]


    I think the problem here is, that you cannot use the Image subsystem (or
    any AWT peering classes) when you are not running within the shell of an
    X-Windows system.
    So, you may need to have an initialized X-Windows running on the server for
    this to work properly.

    You could write your own algorithm so read the file, interpret the data and
    create the proper data for an output file - all from the bytes you read.

    JPEG but is a lot of algorithmic work, and while GIF is easiest to read, it
    has a few peculiarities like animation that can make things harder.

    Cheers.

    Comment

    Working...