By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,899 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,899 IT Pros & Developers. It's quick & easy.

Problem in JSP

P: 30
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.jav acError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateCla ss(JDTCompiler.java:386)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:280)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:259)
org.apache.jasper.compiler.Compiler.compile(Compil er.java:247)
org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:296)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:295)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:245)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)

Java class is:
Expand|Select|Wrap|Line Numbers
  1. package com.test;
  2. import java.util.;
  3. import java.io.;
  4.  
  5. public class FileListing {
  6.  
  7.  
  8. /**
  9. * Recursively walk a directory tree and return a List of all
  10. * Files found; the List is sorted using File.compareTo().
  11. *
  12. * @param aStartingDir is a valid directory, which can be read.
  13. */
  14. public static List&lt;File&gt; getFileListing(File aStartingDir) throws FileNotFoundException
  15. {
  16. validateDirectory(aStartingDir);
  17. List&lt;File&gt; result = getFileListingNoSort(aStartingDir);
  18. Collections.sort(result);
  19. return result;
  20. }
  21.  
  22. // PRIVATE //
  23. public static List&lt;File&gt; getFileListingNoSort(File aStartingDir) throws FileNotFoundException
  24. {
  25. List&lt;File&gt; result = new ArrayList&lt;File&gt;();
  26. File[] filesAndDirs = aStartingDir.listFiles();
  27. List&lt;File&gt; filesDirs = Arrays.asList(filesAndDirs);
  28. for(File file : filesDirs) {
  29. result.add(file); //always add, even if directory
  30. if ( ! file.isFile() ) {
  31. //must be a directory
  32. //recursive call!
  33. List&lt;File&gt; deeperList = getFileListingNoSort(file);
  34. result.addAll(deeperList);
  35. }
  36. }
  37. return result;
  38. }
  39.  
  40. /**
  41. * Directory is valid if it exists, does not represent a file, and can be read.
  42. */
  43. public static void validateDirectory (File aDirectory) throws FileNotFoundException
  44. {
  45. if (aDirectory == null) {
  46. throw new IllegalArgumentException("Directory should not be null.");
  47. }
  48. if (!aDirectory.exists()) {
  49. throw new FileNotFoundException("Directory does not exist: " + aDirectory);
  50. }
  51. if (!aDirectory.isDirectory()) {
  52. throw new IllegalArgumentException("Is not a directory: " + aDirectory);
  53. }
  54. if (!aDirectory.canRead()) {
  55. throw new IllegalArgumentException("Directory cannot be read: " + aDirectory);
  56. }
  57. }
  58. }
  59.  
  60.  
  61.  
Jsp file is:
Expand|Select|Wrap|Line Numbers
  1. &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.io.File,java.util.*,com.test.*"%&gt;
  2. &lt;html&gt;
  3. &lt;body&gt;
  4. &lt;%
  5. try
  6. {
  7. com.test.FileListing tt = new com.test.FileListing();
  8.  
  9. File startingDirectory = new File("D:/eclipse/workspace/cms/WebContent/");
  10.  
  11. List&lt;File&gt; files = tt.getFileListing(startingDirectory); //Error in this line
  12.  
  13. //print out all file names, in the the order of File.compareTo()
  14. for(File file : files )
  15. {
  16. System.out.println(file);
  17. }
  18. }
  19. catch(Exception e)
  20. {
  21. out.println("Error ocurred : "+e);
  22. }
  23. %&gt;
  24. &lt;/body&gt;
  25.  
  26. &lt;/html&gt;
  27.  
  28.  
Thanks in Advance,


V. Prasath.
Apr 8 '09 #1
Share this Question
Share on Google+
1 Reply


dmjpro
100+
P: 2,476
How did you convert JSP from Java? Manually or by some programming. Is that your full JSP? And what are getting that is Syntax error.
Apr 9 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.