简体   繁体   English

使用jsp从远程系统读取文件

[英]Read a file from remote system using jsp

We can read a text file using JAVA program on a localhost. 我们可以在localhost上使用JAVA程序读取文本文件。

My problem is , I want to read a file using JSP which is on a client's system . 我的问题是,我想使用客户端系统上的JSP读取文件。 When he runs a JSP using his browser.This JSP should read the file. 当他使用浏览器运行JSP时。这个JSP应该读取该文件。

Is this possible or not? 这可能吗?

And if yes , how this can be achieved? 如果是的话,如何实现这一目标?

No, it's not possible. 不,这是不可能的。

First of all, because the JSP is excuted on the server, and not on the client machine. 首先,因为JSP是在服务器上执行的,而不是在客户端机器上。

Second, because if a random web page could read files on your computer, it would be a major security risk. 其次,因为如果随机网页可以读取您计算机上的文件,那将是一个主要的安全风险。 You can let the user choose a file and upload it to your web server, though. 但是,您可以让用户选择一个文件并将其上传到您的Web服务器。

Also, JSPs are view components. 此外,JSP是视图组件。 Their goal is to generate markup, and they shouldn't contain any line of Java code: only the JSP EL, and JSP tags. 他们的目标是生成标记,它们不应包含任何Java代码行:只有JSP EL和JSP标记。 For anything else, use Java files. 除此之外,使用Java文件。

Sorry I cant just comment. 对不起,我不能发表评论。 But, wouldn't there be a restriction on the browser not being able to access files on the client? 但是,浏览器无法访问客户端上的文件会不会受到限制?

Perhaps the way to do this is to prompt for the file to be uploaded to be processed. 也许这样做的方法是提示要上传文件进行处理。

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

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