jsf文件怎么打开阿???

jsf文件怎么打开阿???,第1张

1、可以用"Ultraedit"打开。

2、用记事本也可以打开的。

JSF文件

JSF主要由两个部分组成:一套功能强大的API函数,用来表示UI组件、管理组件状态、处理事件、进行输入有效性验证,以及对国际化和可访问性的支持;一套包含各种页面元素的并允许自定义的JSP标签库,用来在JSP页面中显示JSF的界面。通过使用JSF所提供的简单而又实用的模型,任何开发人员都可以快速轻松地开发Web应用程序。他们可以使用大量现成的可重用的UI组件,并将这些组件与数据源连接,还可以很容易地将客户端事件和服务器端的事件处理程序绑定。强大的JSF技术可以很好地处理和管理任何复杂的用户界面,使开发人员可以将注意力集中在应用程序的开发上。

使用jsf加myfaces的upload插件实现上传文件的功能

需要的jar包:tomahawk-1.1.6.jar,jsf-impl.jar,commons-fileupload-1.2.jar,commons-io-1.3.2.jar,commons-el-1.0.jar

程序:

package model.map

import control.MapMDelegate

import java.io.BufferedInputStream

import java.io.FileOutputStream

import java.io.IOException

import java.io.InputStream

import java.text.SimpleDateFormat

import java.util.Date

import java.util.Random

import javax.faces.application.FacesMessage

import javax.faces.context.FacesContext

import org.apache.myfaces.custom.fileupload.UploadedFile

public class FileUploadForm {

public FileUploadForm() {

}

private String name

private UploadedFile upFile

public void setName(String name) {

this.name = name

}

public String getName() {

return name

}

public void setUpFile(UploadedFile upFile) {

this.upFile = upFile

}

public UploadedFile getUpFile() {

return upFile

}

public String upload() throws IOException {

try {

InputStream in = new BufferedInputStream(upFile.getInputStream())

try {

byte[] buffer = new byte[(int)upFile.getSize()]

Date now = new Date()

SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss")

String dt2 = sdf2.format(now)

//取得后缀名

String name = upFile.getName()

int l = name.lastIndexOf(".")

name = name.substring(l)

//生成2位随机数

Random random = new Random()

String sRand=""

String rand = null

for (int count=0count<2count++){

rand=String.valueOf(random.nextInt(10))

sRand+=rand

}

//生成在服务器端保存的文件名

String saveName = dt2 + sRand + name

this.setName(saveName)

String trace = D:\\"+ saveName//本地测试

FileOutputStream fileOutputStream =

new FileOutputStream(trace)//这里可以把上传的文件写服务器目录,或者数据库中 ,或者赋值给name用于文件名显示

while (in.read(buffer) >0) {

fileOutputStream.write(buffer)

}

} catch (Exception x) {

System.out.print("Exception")

FacesMessage message =

new FacesMessage(FacesMessage.SEVERITY_FATAL,

x.getClass().getName(), x.getMessage())

FacesContext.getCurrentInstance().addMessage(null, message)

return null

}

finally {

in.close()

FacesContext facesContext = FacesContext.getCurrentInstance()

facesContext.getExternalContext().getApplicationMap().put("fileupload_bytes",

upFile.getBytes())

facesContext.getExternalContext().getApplicationMap().put("fileupload_type",

upFile.getContentType())

}

System.out.println("End")

return "OK"

} catch (Exception x) {

System.out.print("Exception")

FacesMessage message =

new FacesMessage(FacesMessage.SEVERITY_FATAL,

x.getClass().getName(), x.getMessage())

FacesContext.getCurrentInstance().addMessage(null, message)

return null

}

}

public boolean isUploaded() {

FacesContext facesContext = FacesContext.getCurrentInstance()

return facesContext.getExternalContext().getApplicationMap().get("fileupload_bytes") !=

null

}

}

页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<%@ page contentType="text/htmlcharset=GBK"%>

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

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

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

<f:view>

<html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=GB18030"/>

<title>add-map</title>

</head>

<body>

<h:outputText value="#{MapMDelegate.msg}" style="color:rgb(255,0,0)"/>

<h:form enctype="multipart/form-data">

<t:inputFileUpload value="#{fileuploadForm.upFile}"/>

<br/>

<h:message for="fileupload"/><h:commandButton value="上传"

action="#{fileuploadForm.upload}" />

</h:form>

<h:form>

<br/>

图纸名称 <h:inputText value="#{fileuploadForm.name}" disabled="true"/>

</h:form>

</body>

</html>

</f:view>

记得要在工程的web.xml文件中加入filter

<!--Tomahawk-->

<filter>

<filter-name>extensionsFilter</filter-name>

<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>

<init-param>

<description>Set the size limit for uploaded files.

Format: 10 - 10 bytes

10k - 10 KB

10m - 10 MB

1g - 1 GB</description>

<param-name>uploadMaxFileSize</param-name>

<param-value>10m</param-value>

</init-param>

<init-param>

<description>Set the threshold size - files

below this limit are stored in memory, files above

this limit are stored on disk.

Format: 10 - 10 bytes

10k - 10 KB

10m - 10 MB

1g - 1 GB</description>

<param-name>uploadThresholdSize</param-name>

<param-value>1k</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>extensionsFilter</filter-name>

<url-pattern>/faces/*</url-pattern>

</filter-mapping>

还有把你的程序设置成request哦

<managed-bean>

<managed-bean-name>fileuploadForm</managed-bean-name>

<managed-bean-class>model.map.FileUploadForm</managed-bean-class>

<managed-bean-scope>request</managed-bean-scope>

</managed-bean>


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/6040547.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-12
下一篇 2023-03-12

发表评论

登录后才能评论

评论列表(0条)

保存