Is there a method to convert the javascript file object into java code file object
var files;
to java file object File file =new File();
Like i have a javascript file object var files;
which i have accessed in my jsp code using
js code->
window.location.replace("downloadScreen.jsp?files=" + files);
jsp code-><% String f=request.getParameter("files");
now i want f should be a java file object.what to do?
Asked
Active
Viewed 937 times
0

Mohit Miglani
- 41
- 10
-
What is a "javascript file object" and what is a "java code file object"? Is it source files? Converting a .js file to .java class? In that case, most likely no, although I don't rule out some conversion that does something along those lines to some extent with some success. If you mean an actual file, then, your question is still unclear - opening the same file in JS and Java should give you the same content - there is no special "Java-only readable files" unless we are talking about compiled code or something. – VLAZ Feb 25 '19 at 06:23
-
edited my question. – Mohit Miglani Feb 25 '19 at 06:39
-
OK, so you actually want to pass a value from JS to Java. This is a different question to what I thought you were asking. JS runs in the browsers, and Java runs on the server [more info here](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming). So, you would probably need to either have a form you submit which goes to the server with the value you want or do an AJAX request to send the value to the server. It depends on what you're trying to do and the level of sophistication you want. – VLAZ Feb 25 '19 at 06:43
-
in essence a js object is json(or the other way round: json is a js object), so you can use a json parser(jackson, gson) to create a java object from a js object. Or you can use a js engine in java(nashorn) https://openjdk.java.net/projects/nashorn/ – kai Feb 25 '19 at 07:55