This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

whats wrong with this code?  RSS feed

 
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)
 
Author and ninkuma
Marshal
Posts: 66678
167
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
    Posts: 66678
    167
    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.
     
    Rancher
    Posts: 4686
    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...
     
    look! it's a bird! it's a plane! It's .... a teeny tiny ad
    Rocket Oven Kickstarter - from the trailboss
    https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!