最近在项目中用到不少小东西,希望对大家有帮助
首先:
比如说在web页面打开一个应用程序 (txt doc)
B/S
<a href="http://<%=request.getLocalAddr()%>:<%=request.getLocalPort()%><%=request.getContextPath()%>/UploadFile/文件" target="_blank">click</a>
假如不能成功则在web.xml配置
<mime-mapping> (txt配置)
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
txt请注意文件的编码集 utf-8 否则乱码
C/S
Runtime.getRuntime().exec("rundll32 url.dll FileProtocolHandler file:文件");
文件上传
在form里讲上传文件那定义为FormFile
在页面里设置enctype="multipart/form-data"
上传的控件用的是 struts标签 html:file
FormFile file = Form.getFormFile();取得上传的文件
String fileName=file.getFileName();
InputStream stream=file.getInputStream();
String filePath = request.getRealPath("/UploadFile");//上传到指定的UploadFile包中
ByteArrayOutputStream baos = new ByteArrayOutputStream();
fileName=CurrentTimes.getCurrentTime()+file.getFileName().substring(file.getFileName().lastIndexOf("."), file.getFileName().length());
OutputStream bos = new FileOutputStream(filePath + "/" + fileName);//建立一个上传文件的输出流
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ( (bytesRead = stream.read(buffer, 0, 8192)) != -1)
{
bos.write(buffer, 0, bytesRead);
}
bos.close();
stream.close();
还有用jspsmartupload.jar 上传也十分方便但是pageContext对象在aciton中无法得到 故此放弃
JQuery验证框架validator
将资源导入文件,然后在form提交处写入onsubmit="return Validator.Validate(this,3)"
在需要验证的页面元素中 设置 dataType="验证类型" msg="提示消息" 具体类型以及使用请自行下载帮助
使用起来非常的方便
<!-- -->
分享到:
相关推荐
开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2开发工具 commons-fileupload-1.3.2...
赠送jar包:commons-fileupload-1.4.jar; 赠送原API文档:commons-fileupload-1.4-javadoc.jar; 赠送源代码:commons-fileupload-1.4-sources.jar; 赠送Maven依赖信息文件:commons-fileupload-1.4.pom; 包含...
commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-fileupload-1.2.2commons-...
赠送jar包:commons-fileupload-1.3.3.jar; 赠送原API文档:commons-fileupload-1.3.3-javadoc.jar; 赠送源代码:commons-fileupload-1.3.3-sources.jar; 赠送Maven依赖信息文件:commons-fileupload-1.3.3.pom;...
commons-fileupload-1.0.zip commons-fileupload-1.1.1.zip commons-fileupload-1.1.zip commons-fileupload-1.2.1-bin.zip commons-fileupload-1.3.1-bin.zip commons-fileupload-1.3.1-src.zip commons-fileupload...
commons-fileupload-1.3.1.jar
commons-fileupload-1.2.1-bin commons-fileupload 文件上传 commons-fileupload-1.2.1-bin commons-fileupload 文件上传 jar包 及相关文档
commons-fileupload-1.4.jar
commons-fileupload-1.2.1.jar包;commons-lang-2.3.jar,在使用组件实现文件上传时候要注意前后台的一致性,注意在后台定义File文件对象名要与jsp页面中的file标签name名字一致,前台form标签属性一定要设置为...
赠送jar包:commons-fileupload-1.3.1.jar; 赠送原API文档:commons-fileupload-1.3.1-javadoc.jar; 赠送源代码:commons-fileupload-1.3.1-sources.jar; 包含翻译后的API文档:commons-fileupload-1.3.1-...
commons-fileupload-1.3.3.jar和commons-io-2.6.jar最新版本
赠送jar包:commons-fileupload-1.3.3.jar; 赠送原API文档:commons-fileupload-1.3.3-javadoc.jar; 赠送源代码:commons-fileupload-1.3.3-sources.jar; 赠送Maven依赖信息文件:commons-fileupload-1.3.3.pom;...
commons-fileupload-1.2.2.jar是一款可以实现文件上传功能的jar依赖包,一般进行应用开发的朋友会用到这个开发包,下载后放到应用程序的WEB-INF\lib下就可以正常使用了,有从事web开发的朋友不要错过。
commons-fileupload-1.3.2.jar和commons-io-2.5.jar
利用servlet实现的commons-fileupload的实例。也就是文件上传实例。
java+servlet+commons-io-2.4.jar+commons-fileupload-1.3.jar实现文件的上传与下载
commons-fileupload-1.2.2-bin.zip一个文件上传的第三方插件
上传下载所需jar包,commons-fileupload-1.3.1.jar和commons-io-2.4.jar
commons-fileupload-1.3.jar和commons-io-1.2.jar
commons-fileupload-1.3.2jar包和commons-io-2.5jar包,可以到http://commons.apache.org里面下载最新版本。