简体   繁体   English

将SQL文件名从jsp传递到servlet以进行数据导入

[英]Passing sql file name from a jsp to a servlet for data import

I am retrieving a database by passing an sql source file as following. 我通过传递一个sql源文件来检索数据库,如下所示。
SERVLET CODE: SERVLET代码:

String dbpath="M:\\mydb.sql";       
String [] executeCmd1 = new String[]{current_drive+":\\Program Files\\MySQL\\MySQL Server 5.5\\bin\\mysql", "--user=" + dbuser, "--password=" + dbpassword, dbname,"-e", " source "+dbpath};      
runtimeProcess = Runtime.getRuntime().exec(executeCmd1);

That part is working correctly. 那部分工作正常。 Am stuck in this part where i want the dbpath to be dynamic such that i will use sql file from a html5 卡在这一部分,我希望dbpath是动态的,这样我将使用来自html5的sql文件

 <input type="file" name="myfile">

in whatever local drive the sql file will be and not statically as here 在任何本地驱动器中,sql文件将是静态的,而不是静态的

 dbpath="M:\\biometricdb.sql";

then pass that path to my servlet and receive it as in this code. 然后将该路径传递到我的servlet并按照此代码接收它。

String dbpath=request.getParameter("myfile");

Upon doing so, I am only getting the filename only and not the complete path of the sql file. 这样做后,我只能得到文件名,而不能得到sql文件的完整路径。

Am aware that HTML5: File API doesnt take File absolute path for security reasons. 我知道HTML5:文件API出于安全原因未采用文件绝对路径。 How do i pass that path that file path to my servlet? 如何将那个路径传递给我的servlet? Is there any other way to pass the sql file to the servlet? 还有其他方法可以将sql文件传递到servlet吗?

The path you don't get is the path on the CLIENT which is worthless to you. 您无法获得的路径是CLIENT上的路径,这对您来说毫无价值。 You need to use the SERVER path, since its on the server that the file is going to be processed by mysql. 您需要使用SERVER路径,因为它在服务器上将由mysql处理文件。

So in the uploading code, save the file onto the server, and then use the path of where you saved it to. 因此,在上载代码中,将文件保存到服务器上,然后使用保存文件的路径。

Note: To save it, you either need to be on Servlet API 3.0 and use request.getPart/request.getParts, or you'll need a library like Apache Commons File Upload to read the actual file contents from the request, unless you are using a framework like Spring that can handle that for you somehow. 注意:要保存该文件,您要么需要使用Servlet API 3.0并使用request.getPart / request.getParts,要么需要一个类似Apache Commons File Upload的库来从请求中读取实际文件内容,除非您是使用像Spring这样可以以某种方式为您处理的框架。

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

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