• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

whats wrong with this code?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have made folder named prop in folder where i have all my jsp files
in prop i have notice.txt file


error:org.apache.jasper.JasperException: An exception occurred processing JSP page /notice1.jsp at line 19

16: </head>
17: <body>
18: <%
19: FileInputStream fis=new FileInputStream("prop/notice.txt");
20: Properties p=new Properties();
21: p.load(fis);
22: Enumeration e=p.propertyNames();


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:407)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.io.FileNotFoundException: prop\notice.txt (The system cannot find the path specified)
java.io.FileInputStream.open(Native Method)
java.io.FileInputStream.<init>(FileInputStream.java:106)
java.io.FileInputStream.<init>(FileInputStream.java:66)
org.apache.jsp.notice1_jsp._jspService(notice1_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two big problems:
  • There is Java code in your JSP. Bad bad practice.
  • The relative file path is almost guaranteed not to work as web applications have no deterministic concep of a "current directory".
  •  
    Jatin sachdev
    Ranch Hand
    Posts: 57
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    where to place the text file (in netbeans) then if i want my program to read it???
     
    Bear Bibeault
    Marshal
    Posts: 67418
    173
    Mac Mac OS X IntelliJ IDE jQuery Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Whether you are using Netbeans or not is moot. Where is it placed in regard to the context root?

    When you know that, you can use ServletContext.getRealPath() to get its proper file path.

    And, move the Java code into a Java class where it belongs. It has no business in a JSP.
     
    Rancher
    Posts: 4686
    7
    Mac OS X VI Editor Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Jatin sachdev wrote:where to place the text file (in netbeans) then if i want my program to read it???



    A web application reads relative to the context root, which is defined in the WAR file. Usually, you can put it in the
    web/WEB-INF/classes directory and it will be visibile. You still have to reference it as Bear describes
     
    Jatin sachdev
    Ranch Hand
    Posts: 57
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    its running now......i have placed my properties file in classes/com and read it using...
     
      Bookmark Topic Watch Topic
    • New Topic