У меня есть простая проблема, я делаю простое веб-приложение jsf, которое может загружать файлы, но я продолжал получать
Target Unreachable, identifier 'upload' resolved to null
вот мой класс загрузки
package SimpleLogin;
import java.io.IOException;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import org.apache.commons.io.FilenameUtils;
import org.apache.myfaces.custom.fileupload.UploadedFile;
@ManagedBean
@RequestScoped
public class upload {
private UploadedFile uploadedFile;
public void submit() throws IOException {
String fileName = FilenameUtils.getName(uploadedFile.getName());
String contentType = uploadedFile.getContentType();
byte[] bytes = uploadedFile.getBytes();
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(String.format("File '%s' of type '%s' successfully uploaded!", fileName, contentType)));
}
public UploadedFile getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(UploadedFile uploadedFile) {
this.uploadedFile = uploadedFile;
}
}
и моя страница указателя
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:t="http://myfaces.apache.org/tomahawk"
>
<h:head>
<title>Facelet Title</title>
<h:outputStylesheet name="css/jsfcrud.css"/>
</h:head>
<h:body>
<ui:composition template="./template.xhtml">
<ui:define name="body">
<h:form>
<h:commandLink action="/contacts/List" value="Show All Contacts Items"/>
</h:form>
<h:form enctype="multipart/form-data">
<t:inputFileUpload value="#{upload.uploadedFile}" />
<h:commandButton value="submit" action="#{upload.submit}" />
<h:messages />
</h:form>
</ui:define>
</ui:composition>
о да, вот мой web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</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>
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/login.xhtml</welcome-file>
</welcome-file-list>
Извините за долгую задержку здесь мое лицо config.xml
<faces-config version="2.0"
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-facesconfig_2_0.xsd">
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>SimpleLogin.simpleLogin</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>bean</managed-bean-name>
<managed-bean-class>SimpleLogin.Upload</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope></managed-bean>
<navigation-rule>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-action>
#{simpleLogin.CheckValidUser}
</from-action>
<from-outcome>fail</from-outcome>
<to-view-id>/resultforfail.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>
#{simpleLogin.CheckValidUser}
</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<application>
<resource-bundle>
<base-name>/Bundle</base-name>
<var>bundle</var>
</resource-bundle>
</application>
и мой шаблон
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><ui:insert name="title">Default Title</ui:insert></title>
<h:outputStylesheet name="css/jsfcrud.css"/>
<h:outputStylesheet name="css/cssLayout.css"/>
<h:outputStylesheet name="css/default.css"/>
</h:head>
<h:body>
<div id="top">
<ui:insert name="top">Ini Header</ui:insert>
</div>
<h1>
<ui:insert name="title"></ui:insert>
</h1>
<p>
<ui:insert name="body"></ui:insert>
</p>
<div id="bottom">
<ui:insert name="bottom">Ini Footer</ui:insert>
</div>
</h:body>
в чем проблема?я не могу четко указать класс загрузки?Любая помощь хороша:)