How can i separate fields in JSP from text file? -
i have perl script search latest modified files in specified folders. when search end script put data in text file structure:
[comp] = folder1 [date] = 2015.06.01 08:12 [comp] = folder1 [date] = 2015.06.01 05:27 [comp] = folder1 [date] = 2015.05.31 11:44:44
...etc
for display have use jsp, because server running tomcat.
here's index.jsp:
<%@ page import = "java.io.*, java.util.*" %> <% servletcontext context = getservletcontext(); string file = (context.getrealpath("/list.txt")); string s, list = new string(); try { datainputstream in = new datainputstream( new bufferedinputstream( new fileinputstream(file))); while((s = in.readline())!= null) { list += s + "\n"; } in.close(); } catch(exception e) {system.out.println(e);} %> <pre> <%=list%> </pre>
now, "list" variable contain comp , date fields data.
so, question is, how can separate fields (copm, date) in jsp text file?
thanks answers!
use index keep track of line numbers. if even, add comp list, otherwise add date list.
<%@ page import = "java.io.*, java.util.*" %> <% servletcontext context = getservletcontext(); string file = (context.getrealpath("/list.txt")); string s = new string(); list<string> complist = new arraylist<string>(); list<string> datelist = new arraylist<string>(); int = 0; try { datainputstream in = new datainputstream( new bufferedinputstream( new fileinputstream(file))); while((s = in.readline())!= null) { if(i % 2 = 0) { complist.add(s); } else { datelist.add(s); } i++; } in.close(); } catch(exception e) {system.out.println(e);} %> <pre> <%=complist%> <%=datelist%> </pre>
Comments
Post a Comment