Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Looking for JSP help in multi line text box form submission  RSS feed

 
James Bubenik
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

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.

Can anyone suggest?



My code...

 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some other novice tips that will help you move along:
  • Don't use all uppercase for HTML. That went out in the 1990's.
  • Always use proper indentation for your code, be it Java, HTML or whatever else. Unindented code is not only hard to read, it hides the structure of the code.
  • And, as already noted, never ever ever put Java code in a JSP.
  •  
    James Bubenik
    Greenhorn
    Posts: 2
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Typical developers.  :)
     
    Dave Tolls
    Rancher
    Posts: 2914
    36
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.

    ETA: But seriously.  Do not do this in the JSP!
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!