简体   繁体   中英

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.
SERVLET CODE:

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

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

in whatever local drive the sql file will be and not statically as here

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

then pass that path to my servlet and receive it as in this code.

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

Upon doing so, I am only getting the filename only and not the complete path of the sql file.

Am aware that HTML5: File API doesnt take File absolute path for security reasons. How do i pass that path that file path to my servlet? Is there any other way to pass the sql file to the servlet?

The path you don't get is the path on the CLIENT which is worthless to you. You need to use the SERVER path, since its on the server that the file is going to be processed by 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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