Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

i get errors when using tomahawak inputFileUpload component.

843844Jul 13 2008 — edited Jul 13 2008
Hello everyone. I am a newbie with JSF. I use netbeans 6.1 and apache myfaces and tomahawk libraries. I need to upload a file. I use <t:inputFileUpload /> component of tomahawk but cant put it to work. When i choose the file from the browser and click upload button i get this error on browser.
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class org.apache.myfaces.shared_tomahawk.config.MyfacesConfig
	org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:135)
	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

root cause

java.lang.NoClassDefFoundError: Could not initialize class org.apache.myfaces.shared_tomahawk.config.MyfacesConfig
	org.apache.myfaces.renderkit.html.util.AddResourceFactory.getInstance(AddResourceFactory.java:282)
	org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:126)
	org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
Apache Tomcat/6.0.16
and my jsp page is below
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%--
    This file is an entry point for JavaServer Faces application.
--%>
<f:view>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Endersys License Upload Page</title>
        
        
    </head>
    <body>
        <h:form id="uploadForm" enctype="multipart/form-data">
            <t:inputFileUpload  id="fileUplod" value="#{upload_backing.file}" 
                                storage="file" required="true"/> 
                                
            <h:message for="fileUpload" />
            
            <h:commandButton value="upload" action="#{upload_backing.upload}" />
           
           <h:outputText value="File Uploaded Succesfully" rendered="#{upload_backing.success}"
                         style="color:green" />
           <h:outputText value="Error: File is not uploaded" 
                         rendered="#{upload_backing.success}" style="color:red" />
                         
                         
            
        </h:form>
   

    </body>
</html>
</f:view>
and this is the content of web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
        <param-name>com.sun.faces.verifyObjects</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.validateXml</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>   
    
   <filter>
	<filter-name>MyFacesExtensionsFilter</filter-name>
	<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
    <init-param>
        <param-name>maxFileSize</param-name>
        <param-value>10m</param-value>
        <description>Set the size limit for uploaded files.
            Format: 10 - 10 bytes
                    10k - 10 KB
                    10m - 10 MB
                    1g - 1 GB
        </description>
    </init-param>
    <init-param>
        <param-name>uploadRepositoryPath</param-name>
        <param-value>/tmp</param-value>
    </init-param>
    </filter>

<!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages  -->
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

<!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.)  -->
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>

    </web-app>
and the bean i use is here
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bean.backing;

import java.io.*;
import javax.servlet.http.*;
import org.apache.myfaces.custom.fileupload.UploadedFile;
import javax.faces.context.FacesContext;
/**
 *
 * @author brhn
 */
public class main {

    private UploadedFile file;
    boolean success = false;
    
    public main() {}

    public UploadedFile getFile() {
        return file;
    }

    public void setFile(UploadedFile file) {
        this.file = file;
    }
    
    public void upload() throws IOException {
    
            try {
            
                InputStream stream = file.getInputStream();
                long size = file.getSize();
                byte [] buffer = new byte[(int)size];
                stream.read( buffer, 0, (int)size );
                stream.close();
                success = true;
                
                
        } catch (Exception e) {
            
            success = false;
            
        }
    }
    
    public boolean isSuccess () {
    
        return success;
        
    }
    
    
}
i need to make it work. All helps will be appreciated
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 10 2008
Added on Jul 13 2008
5 comments
552 views