Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2007, 10:29 PM
Registered User
 
Join Date: Jul 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cannot invoke getName() on the array type File[]

This is mySourceCode ...

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.io.File"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <%
        ServletContext sc = request.getSession().getServletContext();
        java.io.File fi = new File(sc.getRealPath("/file"));

        java.io.File listFile[] = fi.listFiles();
        for(int i=0;i<listFile.length;i++){
            out.println("<br><a href=TesDownload?namaFile="+listFile.getName()+">" +listFile.getName() +"</a><br>");
        }

    %>
</body>
</html>

but i have a problem

An error occurred at line: 16 in the jsp file: /file/WEB-INF/index.jsp
Cannot invoke getName() on the array type File[]
13:
14: java.io.File listFile[] = fi.listFiles();
15: for(int i=0;i<listFile.length;i++){
16: out.println("<br><a href=TesDownload?namaFile="+listFile.getName()+">" +listFile.getName() +"</a><br>");
17: }
18:
19: %>


An error occurred at line: 16 in the jsp file: /file/WEB-INF/index.jsp
Cannot invoke getName() on the array type File[]
13:
14: java.io.File listFile[] = fi.listFiles();
15: for(int i=0;i<listFile.length;i++){
16: out.println("<br><a href=TesDownload?namaFile="+listFile.getName()+">" +listFile.getName() +"</a><br>");
17: }
18:
19: %>


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.jav acError(DefaultErrorHandler.java:85)
    org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateCla ss(JDTCompiler.java:435)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:298)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:277)
    org.apache.jasper.compiler.Compiler.compile(Compil er.java:265)
    org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:564)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:299)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:315)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:265)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)

help me please



Fuad Lutfi
 
Old July 13th, 2007, 03:43 AM
Registered User
 
Join Date: Jul 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

listFile array --> listFile[i].getName()

thanks :D

Fuad Lutfi





Similar Threads
Thread Thread Starter Forum Replies Last Post
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
Working with array-type elements tclotworthy XSLT 2 October 11th, 2007 09:27 AM
Passing a Array in of no specifc type.. John Pennington Pro VB 6 1 September 27th, 2006 05:04 PM
<input type="File"> - Specify File Type and Path gp_mk Classic ASP Basics 2 August 2nd, 2004 03:07 AM
How can I invoke an .rtf file with VB? aster Pro VB 6 3 February 13th, 2004 11:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.