jsf上傳文件
① jsf導航配置文件的問題
我們的是直接配置一個filter.xml文件。希望對你有所幫助。
<!-- filters.xml starts -->
<!-- context-params.xml does not work. put here -->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.READONLY_AS_DISABLED_FOR_SELECTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
<param-value>org.apache.myfaces.renderkit.html.util.DefaultAddResource</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.RESOURCE_VIRTUAL_PATH</param-name>
<param-value>/faces/myFacesExtensionResource</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.CHECK_EXTENSIONS_FILTER</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/模塊一.xml,
/WEB-INF/模塊二.xml, /WEB-INF/模塊三.xml
</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
<!--
<description>
This parameter tells MyFaces if javascript code should be allowed in the
rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default: "true"
</description>
-->
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
<!--
<description>
This parameter tells MyFaces if javascript code should be allowed in the
rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default: "false"
Setting this param to true should be combined with STATE_SAVING_METHOD "server" for
best results.
This is an EXPERIMENTAL feature. You also have to enable the detector filter/filter mapping below to get
JavaScript detection working.
</description>
-->
</context-param>
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING_METHOD</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
<!--
<description>
If true, rendered HTML code will be formatted, so that it is "human readable".
i.e. additional line separators and whitespace will be written, that do not
influence the HTML code.
Default: "true"
</description>
-->
</context-param>
<context-param>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
<!--
<description>
If true, a javascript function will be rendered that is able to restore the
former vertical scroll on every request. Convenient feature if you have pages
with long lists and you do not want the browser page to always jump to the top
if you trigger a link or button action that stays on the same page.
Default: "false"
</description>
-->
</context-param>
<!-- WelcomeFile Filter -->
<!--
<filter>
<filter-name>WelcomeFile Filter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.WelcomeFileFilter</filter-class>
<description>
Due to the manner in which the JSP / servlet lifecycle
functions, it is not currently possible to specify default
welcome files for a web application and map them to the
MyFacesServlet. Normally they will be mapped to the
default servlet for the JSP container. To offset this
shortcoming, we utilize a servlet Filter which examines
the URI of all incoming requests.
</description>
</filter>
-->
<!-- JavaScriptDetector Filter -->
<!--
<filter>
<filter-name>javascriptDetector</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.JavaScriptDetectorFilter</filter-class>
</filter>
-->
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>200m</param-value>
</init-param>
<init-param>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>
<filter>
<display-name>Ajax4jsf Filter</display-name>
<filter-name>ajax4jsf</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
<init-param>
<param-name>forceparser</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<!-- filters.xml ends -->
② JSPX和JSFF文件類型之間的區別ADF框架內
JSFF用於在自動進稿器JSPX頁面片段被用於常規JSF頁面
你可以有JSFF內ADF taskflows然後將它們包括內部JSPX頁面。
jsff不是一個可運行的目標。如果你想運行此頁應該包括內部JSPX頁面。 一個更重要的一點是,當我們使用ADF任務流,我們使用jsff片段
或者可以說是: -
.jspx頁面JSP / XML表示 ,它是一個獨立的頁面,這意味著它可以在沒有任何支持或基頁運行。 Jdeveloper中11克Release1支持.jspx頁面,但這不是在JDeveloper11克Release2,Release2支持Facelets的意思.jsf( 明確的是,.jsf和.jsff是不一樣的東西)。
而
.jsff(JSF片段)頁是JSF的一個片段(Java伺服器面)頁,有時頁變得過於復雜和大,這是不容易編輯這些頁,在這種情況下,它應該在一些片段來分割。 JSF頁面可以在一些規模較小的頁面片段被打破,以避免在編輯的困難和保持頁面片段不能獨立運行,它需要.jsf(JSF頁)或 .jspx的基礎(JSP / XML)頁面
註: - (.jsf和.jsff是不一樣的東西)
.jsf VS .jspx
JSPX是按照慣例,一個JSP / XML表示,而.jsf是約定一個個小面表示。 無論是「更兼容」,但Facelets的是推薦的方式前進,只要你是在11.1.2或更高版本。
11.1.2.x使用.jsf為默認值(為Faclets),其中作為11.1.1.x使用.jspx
一般的Facelets被認為是更好的性能,因為它是更嚴格的集成與JSF lifcycle,也不需要運行前被編譯
JSPX文檔和Facelets的機器人支持JDeveloper中11克R2和我們equallly支持它們的功能(雙方存在非常小的差異)
JSPX文件在JDeveloper11克R1的唯一選擇
JSFF用於頁面片段,而JSPX用於普通自動進稿器的網頁,在技術上也可以使用JSPX作為頁面片段。 當您使用JDeveloper向導創建一個頁面片段,默認的擴展名將會jsff。
據甲骨文文件「沒有特殊理由使用.jsff較完整的JSF頁面和頁面片段時,你的工作在Application Navigator在JDeveloper之間的快速分化等。」
③ 跪求jsf文件上傳例子。。
這個還真做過
界面
<h:form id="upLoadExcel" enctype="multipart/form-data" >
請選擇Excel文件 <t:inputFileUpload id="fileupload"
value="#{ExcelListBean.upFile}"
storage="file"
maxlength="200000"/>
<f:verbatim></f:verbatim><br></br><br></br>
<h:commandButton value="提交EXCEL" action="#{ExcelListBean.addWhiteList}" styleClass="formStylebutton" type="submit" />
</h:form>
後台
導的是這個文件
import org.apache.myfaces.custom.fileupload.UploadedFile;
好像要導三個jar..
myfaces-api-1.1.5.jar
myfaces-extensions-1.0.9.jar
myfaces-impl-1.1.5.jar
javax.servlet.ServletContext sc=(javax.servlet.ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext();
String trace=sc.getRealPath("/")+saveName;
System.out.println(".............URL: "+trace);
FileOutputStream fileOutputStream =
new FileOutputStream(trace); //上傳的文件寫伺服器目錄
while (in.read(buffer) > 0) {
fileOutputStream.write(buffer);
}