September 03, 2010, 11:52:26 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: How to Browse Folder in JSP  (Read 1263 times)
0 Members and 1 Guest are viewing this topic.
jazz2k8
Yo Maaan Cheer Up...
Member
*

Reputation: 0
Offline Offline
Posts: 82
Referrals: 0

WWW Awards
« on: February 03, 2009, 09:29:34 AM »

Hi

Can any body give me suggestions on how to choose a  folder in JSP...


As i have tried with SWINGS with JFilechoser....and wrked perfect ...selected a folder and displayed the files in that ...acn you help me ...
thanks
Logged

visit my blog: www.yoteam.co.cc
Javaforums.net :: a community about Java software development.
« on: February 03, 2009, 09:29:34 AM »

 Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« Reply #1 on: February 03, 2009, 07:46:05 PM »

As far as i know, its not possible to show a "file browser" on a JSP or HTML page but judging from the people here: http://www.experts-exchan.../J2EE/JSP/Q_20309435.html
it should work with the code below:

Code
GeSHi (java):
  1. ----------------------------------------
  2.            <table name="slave2" width="800" cellpadding="0" cellspacing="0">
  3.                  <tr>
  4.                        <th>Filename</th>
  5.                        <th>code</th>
  6.                        <th>Filename</th>
  7.                        <th>code</th>                        
  8.                        <th>Filename</th>
  9.                        <th>code</th>                  
  10.  
  11.                  </tr>
  12.                  <%
  13.                        //String expertsLocation = application.getRealPath("/experts") ; //onlyused in a webapp            
  14.                                String  expertsLocation  = "F:\\examples\\sample" ;
  15.                                String[] arEDirs = new File( expertsLocation ).list();
  16.                        Arrays.sort( arEDirs ) ;
  17.                        for( int ii=0 ; ii< arEDirs.length ; ii++){
  18.                              File file = new File(expertsLocation + "\\" +arEDirs[ii]) ;
  19.                              String type = file.isFile() ? " &lt;file&gt;" : "  &lt;dir&gt;"; //file or directory
  20.                              if (ii % 3 == 0){
  21.                                    out.println("<tr><td>") ;
  22.                              }else if(ii % 3 == 1){
  23.                                    out.println("<td>") ;
  24.                              }else{
  25.                                    out.println("<td>") ;
  26.                              }
  27.  
  28.                              out.println( "<a style=\"color:#FF0000\" href=\"expertsLocation/" + arEDirs[ii]+"\" >"+ arEDirs[ii].split("\\.")[0] +"</a> " + ""+ "</td>" ) ;
  29.                              out.println( "<td><a style=\"color:#FF0000\" href=\"experts/code.jsp?file=" + arEDirs[ii] + "\">here</a>") ;
  30.  
  31.                              if (ii % 3 == 0){
  32.                                    out.println("</td>") ;
  33.                              }else if(ii % 3 == 1){
  34.                                    out.println("</td>") ;
  35.                              }else{
  36.                                    out.println("</td></tr>") ;
  37.                              }
  38.                        }
  39.                  %>
  40.            </table>
  41.  
  42.  
  43.  
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
jazz2k8
Yo Maaan Cheer Up...
Member
*

Reputation: 0
Offline Offline
Posts: 82
Referrals: 0

WWW Awards
« Reply #2 on: February 04, 2009, 01:37:00 AM »

m very much impressed with your code...but not meet my requirement...

How to browse a Directory???  is my requirement ...

Logged

visit my blog: www.yoteam.co.cc
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« Reply #3 on: February 04, 2009, 09:27:53 AM »

m very much impressed with your code...but not meet my requirement...

How to browse a Directory???  is my requirement ...



That code snippet browses a directory.
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
   

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.282 seconds with 35 queries.

Google visited last this page Today at 11:13:47 PM