简体   繁体   English

使用JSP从本地文件系统读取文件

[英]using JSP to read a file from the local file system

I need to read a file from the local file system using JSP, save it as a string , and send it to a webservice(deployed using glassfish) for processing. 我需要使用JSP从本地文件系统读取文件,将其另存为字符串,然后将其发送到Web服务(使用glassfish部署)以进行处理。 Can anyone suggest how to perform File IO using JSP? 谁能建议如何使用JSP执行文件IO?

Thanks, Deepak. 谢谢,迪帕克

Doing File I/O from a JSP is the same as doing it normally: Just use the java.io or java.nio classes. 从JSP执行文件I / O与正常进行操作相同:只需使用java.iojava.nio类。 If you need to map a virtual path to a real one, you can use ServletContext#getRealPath . 如果需要将虚拟路径映射到真实路径,则可以使用ServletContext#getRealPath

Technically, I tend to agree with TJ here. 从技术上讲,我倾向于在这里同意TJ。 But actually its not the same, its a bad idea altogether. 但是实际上它不一样,完全是个坏主意。

If you want to upload a file to the server and process it, then use a html form with fileupload field and select the text file and submit the form . 如果要将文件上载到服务器并进行处理,请使用带有fileupload字段的html表单,然后选择文本文件并提交表单。 the file will be uploaded to the server where you can process it 该文件将被上传到您可以在其中处理的服务器

http://www.java-tips.org/java-ee-tips/javaserver-pages/uploading-file-using-jsp.html http://www.java-tips.org/java-ee-tips/javaserver-pages/uploading-file-using-jsp.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM