• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

whats wrong with this code?

 
Jatin sachdev
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


errorrg.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)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
    Author and ninkuma
    Marshal
    Pie
    Posts: 65118
    91
    IntelliJ IDE Java jQuery Mac Mac OS X
    • 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.
     
    Pat Farrell
    Rancher
    Posts: 4678
    7
    Linux Mac OS X VI Editor
    • 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...
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic