| Author |
running linux find command through jsp
|
Sonal Joshiabc
Greenhorn
Joined: Aug 13, 2012
Posts: 3
|
|
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
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14491
|
|
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.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Sonal Joshiabc
Greenhorn
Joined: Aug 13, 2012
Posts: 3
|
|
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
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
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.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: running linux find command through jsp
|
|
|