Hi i know hw to read the textfile using filereader and stringtokenizer used to split the data into token,now i want to know hw to assign the readed value into vector and display it in to the jsp. anybody can help me.
thankyou

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import myPack.Firstapp;


/**
 * @version 	1.0
 * @author
 */
public class Appsecondservlet extends HttpServlet implements Servlet {

	/**
	* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	*/
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
			doPost(req,resp);

	}

	/**
	* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	*/
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
			Firstapp a1=new Firstapp();
		
		//public static void main(String arg[]){
			 				  try
							  {
							  FileReader f2=new FileReader("c:\\NEWFILE.txt");
            
							  BufferedReader input = new BufferedReader(f2);
							  Vector v=new Vector();
								String line = input.readLine();
								while (line!= null) {
								 						 
			StringTokenizer st = new StringTokenizer(line,"\n",true);
		
				while (st.hasMoreTokens()) {
					String next= st.nextToken();	
					v.addElement(next);
					//System.out.println(line);
					System.out.println(next);
						}
						line = input.readLine();
							 		
						//String test=line;
								}
							  
									input.close();
									f2.close();
									 }		
								 catch(IOException e){}
		
						RequestDispatcher disp=getServletContext().getRequestDispatcher("/Secondjsp.jsp");
		req.setAttribute("myapp1",a1);
}
}

In the JSP, you can do the following. This code will print the content of v1 to the JSP page.

<%

     Vector v1 = req.getAttribute("a1");
     Iterator iter = v1.iterator();
     while(iter.hasNext())
     {
      %>
              <%= String.valueOf(iter.next()) %>

     <%
      }
      %>
This article has been dead for over six months. Start a new discussion instead.