• Post Reply Bookmark Topic Watch Topic
  • New Topic

running linux find command through jsp

 
Sonal Joshiabc
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am trying to display names of all images in a particular directory (and all its subdirectories) using the below code.



The code is working fine but I am unable to get the image names in separate lines. Please help

Current Output:
abc.jpguntitled.JPGvivek.jpg

Required Output:
abc.jpg
untitled.JPG
vivek.jpg

Also I want to create links to images such that when abc.jpg is clicked, it should open in same window, say in the right half window. Please help.
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't tell me that you want to do this in a professional webapp.

Not only is the practice of putting blocks of executable Java code in JSPs seriously discouraged, the java.io.File class has all the functionality needed to do a "find" operation in write-once/run-anywhere mode (including filtering names) and without the significant overhead of spawning an independent OS process.

As to why your sample is failing, however, I think it's because you're trying to read the command's input stream when you should be trying to read its output stream.
 
Sonal Joshiabc
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

I used locate command to find .jpg files


and used processbuilder to execute the command.
it is working now. Thanks for your reply
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15715
73
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still, executing a native command in a JSP like this is an ugly, non-portable solution. Tim explained why:
Tim Holloway wrote:Not only is the practice of putting blocks of executable Java code in JSPs seriously discouraged, the java.io.File class has all the functionality needed to do a "find" operation in write-once/run-anywhere mode (including filtering names) and without the significant overhead of spawning an independent OS process.

Your solution is very inefficient, not scalable (when a lot of users use this functionality at the same time, lots of processes will be spawned on the server) and not portable (it will not work if you would have a server running Windows).

You can easily do this in pure Java using methods in the class java.io.File (look it up in the API documentation). That would make your code platform-independent and probably a lot faster.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!