Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Hi,
I am struggling with the following problem. Can somebody pls help me?.
I am developing a wesbite for user can edit their files only, so i am going to develop a page for a Tree Structure in jsp.
I got one java code from internet, that working perfectly in java, it doesn't work after i converted in jsp. I don't know what is the problem in that code. If anybody knows the answer let me know....
When i run that code from jsp it throws the following error;
Error is:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 4 in the jsp file: /tree.jsp
Generated servlet error:
Syntax error on token "<"=", != expected
An error occurred at line: 4 in the jsp file: /tree.jsp
Generated servlet error:
Syntax error on token(s), misplaced construct(s)
An error occurred at line: 4 in the jsp file: /tree.jsp
Generated servlet error:
Syntax error on token ")", : expected
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:386)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:280)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:259)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:247)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Java class is:
package com.test;
import java.util.*;*
*import java.io.*;
public class FileListing {
/**
* Recursively walk a directory tree and return a List of all
* Files found; the List is sorted using File.compareTo().
*
* @param aStartingDir is a valid directory, which can be read.
*/
public static List<File> getFileListing(File aStartingDir) throws FileNotFoundException
{
validateDirectory(aStartingDir);
List<File> result = getFileListingNoSort(aStartingDir);
Collections.sort(result);
return result;
}
// PRIVATE //
public static List<File> getFileListingNoSort(File aStartingDir) throws FileNotFoundException
{
List<File> result = new ArrayList<File>();
File[] filesAndDirs = aStartingDir.listFiles();
List<File> filesDirs = Arrays.asList(filesAndDirs);
for(File file : filesDirs) {
result.add(file); //always add, even if directory
if ( ! file.isFile() ) {
//must be a directory
//recursive call!
List<File> deeperList = getFileListingNoSort(file);
result.addAll(deeperList);
}
}
return result;
}
/**
* Directory is valid if it exists, does not represent a file, and can be read.
*/
public static void validateDirectory (File aDirectory) throws FileNotFoundException
{
if (aDirectory == null) {
throw new IllegalArgumentException("Directory should not be null.");
}
if (!aDirectory.exists()) {
throw new FileNotFoundException("Directory does not exist: " + aDirectory);
}
if (!aDirectory.isDirectory()) {
throw new IllegalArgumentException("Is not a directory: " + aDirectory);
}
if (!aDirectory.canRead()) {
throw new IllegalArgumentException("Directory cannot be read: " + aDirectory);
}
}
}Jsp file is:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.io.File,java.util.*,com.test.*"%>
<html>
<body>
<%
try
{
com.test.FileListing tt = new com.test.FileListing();
File startingDirectory = new File("D:/eclipse/workspace/cms/WebContent/");
List<File> files = tt.getFileListing(startingDirectory); //Error in this line
//print out all file names, in the the order of File.compareTo()
for(File file : files )
{
System.out.println(file);
}
}
catch(Exception e)
{
out.println("Error ocurred : "+e);
}
%>
</body>
</html>Thanks in Advance,
V. Prasath.