I am unbelievably new to any type of Java programming - I am mainly doing Linux scripting. I now have a task to associate a JSP file accessible from browser to scripts in the Linux back end which are performing various tasks and eventually sending an email.
My criteria is:
First input: email address in a text box
Second input: list of files (one file per line) in a text box
JSP code should pass the inputs along to a back end Linux script (input1 = $1, input2 = $2) - the script will then perform it's functions and send an email with the same list of files provided.
From my research thus far, I have found the difference between request.getParameter returning a single value, and request.getParameterValues returning multiple values (which is what I need). My problem seems to be the conversion of string to array when using the request.getParameterValues. When I execute my JSP, I am getting the error:
[Ljava.lang.String;@10181f5b means that files is an array of type java.lang.String and 10181f5b is hashcode of this variable.
I am looking for a simple method of converting my array back to strings so it can be parsed to the Linux script and subsequently considered by this script in the output email.
OR otherwise pass a multi line variable list to the back end script.
First off, all that Java code should be in a servlet.
Indeed it should be in a separate class that the servlet calls, that way you can test the logic without any webapp framework at all. That's a lot easier to debug.
Since you;re using Runtime.exec() it's advisable to read through this article. The recommendations haven't really changed in the 17 years since it was written.
In your case you'll want to use the exec version that takes an array of parameters.
So you'll want to create a new String 1 larger than the files array, consisting of the cmd value and then all the files in the other array.