interesting ? @ servlet reading a txt file
hi friends,
i need ur help for one interesting problem i m facing.
I want to read a txt file and wanna display the text from that file into an html, using a servlet.A txt file contains sentences( words with spaces in between ).When servlet reads the file, it is reading the whole sentence ,but while displaying that sentence, it is just showing the first word of the sentence.
html is not able to read the space between the words.
so what do i suppose to do now.
waiting for ur replies.......
thanx
amit
[559 byte] By [
amit_vj] at [2007-9-26 1:17:42]

hi friends ,
i m giving the code , just give it a try//
This is a servlet
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class AdminGraphServlet extends HttpServlet
{
Properties ht;
FileInputStream fin;
FileOutputStream fout;
String s15,st;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException,ServletException
{
ht = new Properties();
try
{
fin = new FileInputStream("Data.txt");
}
catch(FileNotFoundException e)
{
System.out.println("FileNotFound");
}
try
{
if(fin != null)
{
ht.load(fin);
s15 = (String)ht.get("title");
fin.close();
}
}
catch(IOException e)
{
System.out.println("Error Reading File");
}
PrintWriter out = res.getWriter();
res.setContentType("text/html");
out.println("<html><body>");
out.println("<form method=post action=http://localhost:8080/servlet/MyServlet>");
out.println("<table><tr>");
out.println("<tr><td>Title</td>");
out.println("<td><Input Type=Text name=title value="+ s15 +"> </td></tr>");
out.println("</table>");
out.println("<input type=submit name=submit value=submit>");
out.println("<input type=hidden name=check value=save>");
out.println("</form>");
out.println("</body></html>");
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
String Scheck = req.getParameter("check");
PrintWriter out1 = res.getWriter();
String ttl = req.getParameter("title");
if(Scheck.equals("save"))
{
ht.put("title",ttl);
fout = new FileOutputStream("Data.txt");
ht.store(fout,"Data");
fout.close();
}
out1.println("<html><body>");
out1.println("<h1>Stored This Data Successfully</h1>");
out1.println("</html></body>");
}
}
-
txt file is having a line
title=Are you smart enough?
The servlet should display this sentence in a text box.
But it is displaying only "Are".
still waiting...
have nice time..
amit