How to read text file via JSP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rkyakkala
    New Member
    • Oct 2010
    • 11

    #1

    How to read text file via JSP

    Hi,

    i am unable to read txt file from jsp. i am getting null pointer exception.

    path of jsp: WEB-INF/views/main.jsp
    path of txt: WEB-INF/views/ServerDetails.t xt

    Following is the code...please suggest where can i make changes to solve the issue.
    Code:
    <%
    BufferedReader input = null;
    String serverName;
    try {
    	input = new BufferedReader(new FileReader("ServerDetails.txt"));
    } catch (FileNotFoundException e1) {
    	e1.printStackTrace();
    }
    String line = "";
    try {
    	while ((line = input.readLine()) != null) {
    	  System.out.println(line);
    %>
    serverName=request.getServerName();
    <%	  if(line.equalsIgnoreCase(serverName)){
    %>
    <H4 align="right">
       out.println("you have entered into primary server");
     </H4>
    
    <%	  }else{%>
    <H4 align="right">
      out.println("you have entered into secondary server");
    </H4>
    <%	  }
    
    }
    	input.close();
    } catch (IOException e) {
    	e.printStackTrace();
    }
     %>
    regards,
    rama
Working...