This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to read text file content line by line" Watch "how to read text file content line by line" New topic

how to read text file content line by line

ibnu ros

Joined: Nov 28, 2012
Posts: 2
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" "">
<html xmlns="">
<%@ taglib uri="" prefix="fmt"%>
<%@ taglib uri="" prefix="fn"%>
<%@ taglib uri="" prefix="sql"%>
<%@ taglib uri="" prefix="c"%>

<%@ page import="*" %>
<%@page import=""%>
<%@page import=""%>

<title>File Handling in JSP</title>


<%--<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}"/>
<%--<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>
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60766

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

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