By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,423 Members | 2,551 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,423 IT Pros & Developers. It's quick & easy.

hw to assign value and display it into the jsp through servlet

P: 1
Hi i am shiyam,

i am having some problem in java, i am basic java programmer.
i have to write one program is writing the data into textfile name "newfile.txt" from one servlet and read it from another servlet its work but i want to know hw to deploy the readed input from textfile is displayed in jsp through servlet2.
here is my code
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 {


* @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[]){
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,";");
while (st.hasMoreTokens()) {
String next= st.nextToken();


line = input.readLine();

} catch(IOException e){}

RequestDispatcher disp=getServletContext().getRequestDispatcher("/Secondjsp.jsp");

help me thankyou
Feb 4 '08 #1
Share this Question
Share on Google+
1 Reply

P: 13,264
1.) Please use code tags when posting code.
2.) You should set the attributes before calling getRequestDispatcher.
Feb 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.