473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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.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,";");
while (st.hasMoreTokens()) {
String next= st.nextToken();
a1.setFinNo(req.getParameter("next"));

v.addElement(next);
//System.out.println(line);
//System.out.println(next);


}System.out.println("\n");
line = input.readLine();
}
input.close();
f2.close();


} catch(IOException e){}

RequestDispatcher disp=getServletContext().getRequestDispatcher("/Secondjsp.jsp");
req.setAttribute("myapp1",a1);
}
}


help me thankyou
Feb 4 '08 #1
1 2128
r035198x
13,262 8TB
1.) Please use code tags when posting code.
2.) You should set the attributes before calling getRequestDispatcher.
Feb 4 '08 #2

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

Similar topics

2
by: kaiwing18 | last post by:
Hi, I have a following jsp file called "showAsset.jsp" : <form action="showAsset.jsp" method="post"> <tr BGCOLOR=YELLOW> <td><input name="sort" type="submit" value="Asset_Number" > </td>...
1
by: Hai Tran | last post by:
Any help is appreciated. Installed Tomcat 4.1 and Mysql on a WinXP. I've manage to get Tomcat up and was able to view my first application ( myhome ) simple home page. Tomcat was installed under...
9
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key"...
1
by: efiedler | last post by:
Hi - I have the following input field on my html page: <input type="image" name="submit" id="submit" src="c:\image.jpg" value="image.jpg"> I also have another input field on the form that is...
2
by: Harry Stangel | last post by:
Noble reader, My goal is to obtain the current time on the web server and display it in the client's browser. I want the server time displayed independent of the client's current clock setting,...
8
by: Ryan | last post by:
I have a hidden field as such: <INPUT TYPE=\"hidden\" name=xmlfield > I have a button that i want to use to call a function to change the value: <INPUT TYPE=submit VALUE="Display XML"...
4
by: Bilwin | last post by:
Hi friends, I would like to know how can i pass values to AJAX form from a servlet and how to display that value in a drop down box. Plz help me on this since i am a newbie to this. Thanks...
1
by: Java Kumar | last post by:
Hi Pals, I need your help regarding following problem.Im working in MVC model application which has jsp, servlet,and bean file. By the flow of application , I have to display datas in jsp page...
3
by: vijaykumardahiya | last post by:
Hello To Every One, I want to know that when I upload the File like a image from html page Its not show on servlet page using appropriate logic. I read the FileUpload Home page.But I am still...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.