Get dir listing in servlet
Hi all,
I have a problem with a servlet:
I am trying to get a String array of all the filenames in a directory. Is this possible in a servlet?
I am using tomcat 5.0.
this is my code so far:
ServletContext context = getServletContext();
URL url = context.getResource("/txt/");
String loc = url.toString();
File dir = new File(loc);
String[] files = dir.list();
for (int i = 0; i < files.length; i++) {
System.out.println(files);
can anyone help?
rntz
I am trying to get a String array of all the
filenames in a directory. Is this possible in a
servlet?If the directory is on the same server where the servlet is running, sure it is.
this is my code so far:
ServletContext context =
ontext = getServletContext();
URL url = context.getResource("/txt/");
String loc = url.toString();
File dir = new File(loc);
String[] files = dir.list();
for (int i = 0; i < files.length; i++) {
System.out.println(files);
can anyone help?
Not really. You haven't said what your problem is, or even if you have a problem.
Similar Messages
-
How do I get a list of files in the DataDrvUser Dir programatically (no dialogs)
I have version 8.1.1292 of Diadem. I wish to get a list of files in a directory without using a dialog.
Hello Sweeten
Attached are two snipits of code, hope this helps
The following sub reads all the folders in a root folder. Note the use the FSO or file system object. The FSO has a number of properties and methods for working with files and folders, would definetly check it out.
Sub ReadProjects()
'This sub reads all the Folders in the root
Set fso = CreateObject("Scripting.FileSystemObject")
Set Folder = fso.Getfolder(RootPath_)
Set Folder = Folder.SubFolders
i=1
For Each SubFolder In Folder
LstStates.Items.add SubFolder.name,i
i=i+1
Next
End Sub
This next code snipit reads all the files of a certain extention (i.e. LPD,DAT)
Sub ReadProjectFiles()
Dim fso,PathName,LvdNames,GraNames,path
Dim x,y,z
x=1:y=1:z
=1:w=1
Set fso = CreateObject("Scripting.FileSystemObject")
Set Folder = fso.Getfolder(ProjectPath_)
Set Files = Folder.Files
For Each file In files
Select Case file.type
Case "LPD File"
LstGraph.items.add file.name , x
x=x+1
Case "DAT File"
LstData.Items.add file.name , y
y = y+1
Case "LVD File"
LstView.Items.add file.name , z
z = z+1
End Select
Next
Let me know if this is helpful
Tom Ferraro
DIAdem Product Manager
512-683-6841 -
How to get javabean data in Servlets.( JavaBean -- Servlet(Controller)
how to get javabean data in Servlets.
1) I am using name ,password in Jsp(View )
2) when I submit this Bean will be called and Setter methods will be called .
3) In ServletController (controller) I want to get data of javabean.
In this I have to do validation of user.
I want to pass the javabean obj as like -->
request.getAttribute("beanObj");
My intention is to get all the poperties in javabean by passing bean id
or beanobj ,
Is there any way to get all the data using bean id or beanObj.
Plz Reply,Now in the Servlet we can get the same bean by this code:
PageContext pageContext = JspFactoryImpl.getDefaultFactory().getPageContext(this, request, response, null, true, 8192, true);
UserBean userbean = (UserBean)pageContext.getAttribute("userbean", PageContext.SESSION_SCOPE);
String userid = userbean.getUsername();
For this code to work it is needed to import 2 files:
import org.apache.jasper.runtime.JspFactoryImpl;
import javax.servlet.jsp.PageContext;
The JspFactoryImpl is in jasper-runtime.jar file provided in tomcat dir.It seems to me that you are exactly knowing what you are doing :-(
You can get a Bean stored in a Session by
request.getSession().getAttribute("userbean");
In the login.jsp page for example we have the code
<jsp:useBean id="userbean" scope="session"class="com.newproj.UserBean" />
<jsp:setProperty name="userbean" property="*" />the jsp:setProperty is not called when you click on the submit button
if fills the bean with the request values from the previous request.
andi -
How do i get a list of httpsessions currently active in container
what is the object that i can interact with to get a listing of active httpsessions
within my application context (servlet container) at any given time? i know i
can setup a listener, is this the only way? is there now direct api?
thanks
I replied to this question in another email thread...
"Vinod Mehra" <[email protected]> wrote in message
news:<[email protected]>...
> Here is a jsp to give you an idea. Unfortunately the session timeout
> (max-inactive-interval) is not exposed in the runtime mbean. So you will
> have to hardcode it for now. If you want it be exposed please ask support
> for a patch.
>
> <%@ page import="weblogic.management.runtime.ServletSessionRuntimeMBean,
> weblogic.management.MBeanHome,
> weblogic.management.Admin,
> java.util.Date,
> java.util.Set,
> java.util.Iterator,
> weblogic.servlet.security.ServletAuthentication,
> weblogic.management.runtime.WebAppComponentRuntimeMBean"
%>
> <pre>
> <%!
> private static final long TIME_OUT = 10; // seconds
> %>
> <%
> // login as system user
> // FIXME: don't hardcode username/passwords
> ServletAuthentication.weak("system", "gumby1234", request, response);
>
> MBeanHome home = Admin.getInstance().getMBeanHome();
> if (home != null) {
> Set mbeanSet = home.getMBeansByType("ServletSessionRuntime");
> Iterator mbeanIterator = null;
> mbeanIterator = mbeanSet.iterator();
> while (mbeanIterator.hasNext()) {
> ServletSessionRuntimeMBean runtime =
(ServletSessionRuntimeMBean)mbeanIterator.next();
> WebAppComponentRuntimeMBean parent = (WebAppComponentRuntimeMBean)
runtime.getParent();
> out.print("ContextPath: " + parent.getContextRoot() +
> " LastAccessedTime: " + new
Date(runtime.getTimeLastAccessed()));
> if (hasSessionExpired(runtime)) {
> out.println(" <b>Invalidating expired session!!</b>");
> runtime.invalidate();
> } else {
> out.println(" Session is still good");
> }
> }
> }
> %>
> <%!
> private boolean hasSessionExpired(ServletSessionRuntimeMBean runtime) {
> return (runtime.getTimeLastAccessed() < (System.currentTimeMillis() -
TIME_OUT * 1000));
> }
> %>
>
> hth,
> Vinod.
>
"Randheer Gehlot" <[email protected]> wrote in message
news:[email protected]...
>
> Vinod,
> This class "ServletSessionRuntimeMBean" does'nt give you list of
all
> the active sessions in memory. Is there any class which holds list of all
active
> sessions in memory ?
>
> Thanks..
> "Vinod Mehra" <[email protected]> wrote:
> >If you have session monitoring turned on ...
> >
> >weblogic.xml:
> >
> > <container-descriptor>
> > <session-monitoring-enabled>false</session-monitoring-enabled>
> > </container-descriptor>
> >
> >... then you should be able to lookup the runtime mbeans
> >(ServletSessionRuntimeMBean).
> >
> >This is what the admin console also uses.
> >
> >--Vinod.
> >
> >"ke" <[email protected]> wrote in message news:[email protected]...
> >>
> >> what is the object that i can interact with to get a listing of active
> >httpsessions
> >> within my application context (servlet container) at any given time?
> > i
> >know i
> >> can setup a listener, is this the only way? is there now direct api?
> >>
> >> thanks
> >
> >
>
-
How do I get a list of directories and sub-directories?
Hi All,
I'm new to Java and have a couple of questions that are really stumping me and I sure could use some help.
Question 1:
I have this class file that I want to return back me a list of directories and only directories, not files. I can't figure out how to do this. I know I need to use the isDirectory() function but I can't figure out how to use it. The class file currently is returning back both directories and files. Please help!
Question 2:
Once I get the list of directories, I need to also get a listing of all subdirectories to form a directory tree starting at my File dir value (example: C:\Windows) in the constructor. Any ideas?
Thanks
import java.io.*;
public class DirList {
private String list = "";
public DirList(File dir){
File f = new File(dir.toString());
String[] files = f.list();
for ( int i=0;i<files.length; i++ ){
list += files[i] + "\n";
} // end for
} // end constructor
public String getList(){
return list;
} // end method getList
} // end class DirListI'm not familiar of the recursion technique that you speek of. If
this would work, please share it with me.Okay, i'll try, I assume that you don't care what level a subfolder is right! With a selected folder (from fileChooser), you want to obtain a list of all subfolders.
After you have select a folder from the filechooser
import java.io.File;
import java.util.ArrayList;
public class AllSubFolders
private static ArrayList allSubFolders = new ArrayList();
public static void main(String [] args) {
File selectedFolder = ....; //a folder seleted from the filechooser
getSubFolder(selectedFolder );
public static void getSubFolder(File aFolder) {
File[] file = aFolder.listFiles();
for (int n = 0; n < file.length; n++) {
if (file[n].isDirectory()){
allSubFolders.add(file[n]);
System.out.println(file[n].getAbsolutePath());
getSubFolder(file[n]); //recursion method call
}You can see that getSubFolder() method call it self, it will do right down to the end of the tree, try it out by replacing the line
File selectedFolder = ....; to
File selectedFolder = new File("c:\\yourFolder\\"); -
How to get a list of uncompressed files in ms Windows XP?
I am running XP sp3. How can I get a list of uncompressed files on my hard drive? Is there like an fsutil /s, dir /s, or ls -la command that might work? Do I need to use a for loop in batch cmd file? Or is there a sysinternals
command equivalent to streams /s that might do the trick that anyone knows about?Yes, thanks, that is one way I already knew about. I want a list. So yes I could take each of 100,000 files and note which ones are black and for each of them hit properties and cut and paste into notepad a file saved as "uncompressed.txt".
I was hoping to avoid doing that work, since it would take a lot of time. Do you know of a faster way? Is there a sortable file field, like "status" or "attributes" that would work?
Jason -
Problem with getting a list of files in a directory
I'm trying to get a list of files in a particular directory. The problem is I'm also getting a listing of all the sub-directories too. Here is my code:
File directory = new File(dir);
File[] filelist;
filelist = directory.listFiles();
for(int i=0;i<filelist.length;i++)
System.out.println("FileName = " + filelist.getName());
What am I doing wrong?
Thanks
BradYou are not doing anything wrong. You just have to test whether a given file is a subdirectory:
File directory = new File(dir);
File[] filelist;
filelist = directory.listFiles();
for(int n = 0; n < filelist.length; n++) {
if (!filelist[n].isDirectory())
System.out.println("FileName = " + filelist[n].getName());
}Søren Bak -
Hello all,
I have a question about printing a list on my JSP. I create a list with a tree like view. I have done this and when I do System.out.println() on my class where I run the sql statement, he shows the actual list. But now I most post this throw my servlet on to my JSP. But I can't figure out how this must be done.
My code for the class is:
public static List Maaktree(int Parent, int level) {
Connectie Dbc = Connectie.getInstance();
List Tree = new LinkedList();
Mappen mappen = new Mappen();
ResultSet rs;
String Query = "select * from Mappen where Parent ='"+Parent+"'";
rs = Dbc.execQuery(Query);
try {
while (rs.next()) {
System.out.println(level + "|" + rs.getString("Mapnaam"));
Tree.add(Maaktree(rs.getInt("Map_id"),(1+level)));
catch (Exception e) {
e.printStackTrace();
return Tree;
}on my servlet I do the next
int Parent = 0;
List Tree = Mapmutaties.Maaktree(Parent, 1);
request.setAttribute("Tree", Tree);
RequestDispatcher ReqD = getServletContext().getRequestDispatcher(
"/Tree.jsp");
if (ReqD != null)
ReqD.forward(request, response);And on my JSP I do like this
<%
java.util.ListIterator pos = null;
java.util.LinkedList Tree = (java.util.LinkedList)request.getAttribute("Tree");
if (Tree != null) pos = Tree.listIterator(0);
%>
<html>
<head>
<title>
</title>
</head>
<body bgcolor="#ffffff">
<b>Mapnaam</b>
<%
if (pos != null)
while(pos.hasNext())
Business.Mappen mappen = (Business.Mappen)pos.next();
%>
<%=mappen.getMapnaam()%>
<%
%>
</body>
</html>But this gives an error. I suspect on the line "Business.Mappen mappen = (Business.Mappen)pos.next();". Because when I remove this line there is no problem. But I can't get the list shown on my JSP.
Does anyone know how to print the list on my JSP.
Thanx,
Henkand what is your error exactly? have you got a stack trace?
-
Unable to get area list, access projects
I'm running RoboHelp Server 9 and I have two issues that could be related.
First, when I attempt to publish WebHelp Pro from RoboHelp, I am unable to select a Help Area in the SSL dialog. I receive a message stating, "Unable to get area list from server." I opened the RoboHelp Server Web Administrator and verified that the areas are listed.
Second, when I go into the server and open the RoboHelp Server Web Administrator and select Projects, I receive a message stating, "Communication error. Server is refreshing project data. Try reloading projects pane in a little while."
I am at a complete loss. Here are things that I or my IT department have tried to do to fix this issue. None of these have worked:
Change the "reindex" property in the robohelp_server.properties file
Increase the PermSpace available to Tomcat:
Run the tomcat-install-dir>/bin/tomcat6w.exe file to open the Apache Tomcat Properties dialog box.
Verify that the Maximum Memory Pool setting is not blank. If it is blank, then specify a value, such as 512 MB. Make sure that the Maximum Memory Pool and XX:MaxPermSize values don't add up to more than the actual memory you can make available to Tomcat.
Restart Tomcat.
Wait 5 – 10 minutes after you publish your project to make sure that the data structure is loaded.
Rebooted the server
Removed recent updates from Adobe and Windows.
Tried using Firefox browser
I appreciate any help that can be offered.
Also note that this was not a problem before. I was able to successfully publish to the server, then suddenly I could not.Hi Shannon.
The step that puzzles me is "Removed recent updates from Adobe and Windows". Could you expan on what the Adobe updates were? The reason I ask is that in my experience the application set-up (e.g. Tomcat + RHS) does not react well to removing things. You may have been OK just removing updates but as you have to install the applications in a precise order, removing updates could have messed with the communication between them.
You certainly seem to have gone through the steps we normally advise in this situation. You could try connecting to the database you are using. If you respond it would be useful to have further information about the physical server and database configuration you are using. -
Getting the list of files in a directory by their last modified date
Dear friends,
I want to get the list of files in a directory sorted by their last modified date.
By default the file.list() or listFiles() return files sorted by their name in ascending order.
Please give me your suggestions.
Thanks in advance,
James.Thanks friend,
I myself got the answer
here is my code:
public File[] getSortedFileList(File dir){
File[] originalList = dir.listFiles();
int numberOfFiles = originalList.length;
File[] sortedList = new File[numberOfFiles];
long[] lastModified = new long[numberOfFiles];
for(int i = 0; i < numberOfFiles; i++){
lastModified[i] = originalList.lastModified();
Arrays.sort(lastModified);
for(int i = 0; i < numberOfFiles; i++){
for(int k = 0; k < numberOfFiles; k++){
if(originalList[k].lastModified() == lastModified[i])
sortedList[i] = originalList[k];
System.out.println("The sorted file list is:" + sortedList[i]);
return sortedList; -
Outputing a dir listing for use as a file sorter
hi all
i was working on using an external *.exe to encode some data and i
need to take a dir listing in so that i can apply the encoding to
certain files, but i am having a little diffuculty in in outputting a
text file from which to scan, i have
i am using labview 6, and the main vi elements i'm using for this
proccess is the list dir vi index array vi and write chars to a file
vi, but i cannot get the file names on a new line for each one, they
are all after each other with one space....
i know in text based programing you can use \n or similar to solve
this, but i am at a loss here with labview
if any one could help i would be most grateful
petermany thanks! i don't know how i could have missed that! :-)
"Greg McKaskle" wrote in message
news:[email protected]..
> > i was working on using an external *.exe to encode some data and i
> > need to take a dir listing in so that i can apply the encoding to
> > certain files, but i am having a little diffuculty in in outputting a
> > text file from which to scan, i have
> > i am using labview 6, and the main vi elements i'm using for this
> > proccess is the list dir vi index array vi and write chars to a file
> > vi, but i cannot get the file names on a new line for each one, they
> > are all after each other with one space....
> > i know in text based programing you can use \n or similar to solve
> > this,
but i am at a loss here with labview
> > if any one could help i would be most grateful
>
>
> The string palette has constants for different linefeed, carriage
> return, or the platform adapting end of line. If you add this
> string character between names, that should get you started.
>
> Greg McKaskle
> -
How to get the list of query parameters
Say I have an URL like the following:
http://localhost/test.jsp?EmpID=1&DeptID=2
and I want to get the list "EmpID=1&DeptID=2" into a String object. How could I do that?
Thanks.
MandyOkay. I found out I missed some steps I should do before I could use the jml tags. After I added the ojsputil.jar to my classpath And put the following line to my jsp page:
<%@ taglib uri="../WEB-INF/jml.tld" prefix="jml" %>
I still got the following error. Why?
Exception:
javax.servlet.jsp.JspException: Invalid 'in' attribute in foreach enumeration
at oracle.jsp.jml.tagext.JmlForeach.doStartTag(JmlForeach.java)
at zydeco.login._jspService(_login.java, Compiled Code)
at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java)
at oracle.jsp.app.JspApplication.dispatchRequest(JspApplication.java)
at oracle.jsp.JspServlet.doDispatch(JspServlet.java)
at oracle.jsp.JspServlet.internalService(JspServlet.java, Compiled Code)
at oracle.jsp.JspServlet.service(JspServlet.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
at org.apache.jserv.JServConnection.processRequest(JServConnection.java)
at org.apache.jserv.JServConnection.run(JServConnection.java)
at java.lang.Thread.run(Thread.java:479)
Thanks.
Mandy
null -
In previous versions of i Tunes I could highlight a song in my library and a genious list would show on the right side of the screen listing songs that were like the one highlighted. Now I do not get that list. Is there a way to get that back?
Hi again Bob,
I believe I've found the feature you were speaking about now. Information on the "In the Store" feature of iTunes can be found here:
Apple - iTunes - Inside iTunes - Using In the Store from within your iTunes Library.
http://www.apple.com/itunes/inside-itunes/2013/01/using-in-the-store-from-within -your-itunes-library.html
Thanks for using the Apple Support Communities. Have a good one!
-Braden -
Is there a way of getting a list of upcoming alerts/alarms and their times?
I'd like to get a list of alert times, so that I can see if I have any that will be going off in the middle of the night!
Many months back, I purged those pesky midnight alerts by scrolling through week by week and looking for the all-day events and checking each one. It was a chore.
Now, due an odd synching issue between iCal and an app, I'm a tad concerned that some late night alerts may have been set, or PMs may have changed to AMs, or other oddities introduced. I'd like to scan a list of alerts for the next several months to ensure that none are set to go off during the sleeping hours!
Just browsing events (say week by week) doesn't help me because they could have alerts set for all sorts of different times (or no alerts at all). If there isn't a way of listing the alerts, then I'll have to go through each individual event/to do to check its alert and time-- and there are hundreds!
Hope this makes sense.Try this in Script Editor - the list of alarms will be in the result pane.
AK
click here to open this script in your editor<pre style="font-family: 'Monaco', 'Courier New', Courier, monospace; overflow:auto; color: #222; background: #DDD; padding: 0.2em; font-size: 10px; width:400px">tell application "iCal"
set Alarming to ""
set MyCalendars to every calendar where writable of it is true
repeat with ThisCal in MyCalendars
set MyEvents to events of ThisCal
repeat with ThisEvent in MyEvents
repeat with ThisAlarm in (display alarms of ThisEvent) & (sound alarms of ThisEvent)
set AlarmTime to (start date of ThisEvent) + (trigger interval of ThisAlarm)
set GotOne to ((name of ThisCal) & ": " & (summary of ThisEvent) & ": " & (start date of ThisEvent as string) & " alarm " & trigger interval of ThisAlarm as string) & " minutes."
set Alarming to Alarming & GotOne & return
end repeat
end repeat
end repeat
end tell
Alarming
</pre> -
How can I get a list view after selecting "see all"?
I just updated to iTunes 12. I've looked on the net for this but couldn't find anything on it.
Previously when I searched for something in the iTunes store I'd pick a certain category of media (podcasts, for example). It would give me the first few results and then I could select "see all." Then get a list view and sort it.
Now when I click on "see all" I get an album cover view. NOT a list view. And I have no way to sort the results. I usually sort by time.
What's odd is when I'm still on the initial page you get after making a search I *can* sort the results. But only the first 10.
Basically, I need a way to sort all of my search results by time. Either after selecting "see all" or having iTunes show many more than 10 results.
This was possible (and the default, I think) in previous versions. I've looked through every menu and I don't see a way to turn this functionality back on.
Thanks.Hi,
There is no such PowerShell command can achiev this. Maybe you can use a script to get the user name with folder redirection enabled. However, I am not familiar with writing script, and it would be better for you to ask in script forum below for professional
assistance:
http://social.technet.microsoft.com/Forums/en-US/home?forum=ITCG&filter=alltypes&sort=lastpostdesc
Best Regards,
Mandy
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]
Maybe you are looking for
-
Can we Hide Measure Folders from a Read Only Session?
Hi , I have implemented security on my workspace by scoping the dimensions and hiding the cubes.It worked. For hiding measure folders, i did similar to hiding of cubes, but it did not work. It threw an error message : ERROR: (ORA-34706) ACCOUNT_BW.ME
-
I upgraded to snow leapord and now when I try to open some of my pictures in Iphoto I get a "!". They are still in the thumbnails but when I click on them they wont open. Any help out there?
-
HT4623 Update ios not working. Please help
I have updated iTunes, My iPhone 4 is on ios 4.3. Nothing else has worked to update ios. So I manually downloaded ios 5. When I held shift on update and selected the ios 5 it worked.Now that I have the update it gets stuck on "preparing software" and
-
Want to develop a booking calender in oracle XE- Step by step process
I want to develop a booking calendar for meeting rooms, where a person should be able insert time (from and til) and able to view available rooms at that particular time. In application (Page 1) it should show registration form with following insert
-
Mac G4 Cube with OS 10.3.9 Start-up/HD issues
Hi. I've gone through a number of these posts to see what suggestions are here, but decided to ask for a straight answer from any one kind enough to answer. Starting up my 2000 G4 Power PC Cube gives me a number of different start-up failure scenerio