File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes how to read text file content line by line Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "how to read text file content line by line" Watch "how to read text file content line by line" New topic
Author

how to read text file content line by line

ibnu ros
Greenhorn

Joined: Nov 28, 2012
Posts: 1
can any body help me how to read text file line by line using jstl

below is my code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%@ page import="java.io.*" %>
<%@page import="java.io.FileReader"%>
<%@page import="java.io.BufferedReader"%>

<head>
<title>File Handling in JSP</title>
</head>

<body>

<%--<c:set var="test" value="test1"/>--%>
<%
BufferedReader reader = new BufferedReader(new FileReader("C:/apache-tomcat-6.0.16/webapps/ROOT/uspmp2/POLI20120627.txt"));
StringBuilder sb = new StringBuilder();
String line;

while((line = reader.readLine())!= null){
sb.append(line.substring(0,2) + "<br>");

}

%>
<c:out value="${sb}"/>
<c:set var="test" value="${sb}"/>
<%
//out.println(sb.toString());
%>
<%--<c:import var="data" url="POLI20120627.txt" scope="session"/>--%>

<%--<c:out value="${data}"/>--%>
<%--<c:forTokens items="${data}" delims="|" var="name">
<c:out value="${name}"/><p>
</c:forTokens>--%>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56192
    
  13

There is no JSTL mechanism to read files. That is not something you should be doing in the JSP, but in the servlet controller.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to read text file content line by line
 
Similar Threads
not able to populate textfield using ajax, but select is working fine
NumberFormatException when running a JSP
Internationalization of web service
error in ArrayList in JSP
What is the point of c:out ?