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]
# 1
You need to fix your code. Obviously it is trying to do something with the words but failing. That's the best I can do from the minuscule description of your problem.
DrClap at 2007-6-29 0:47:37 > top of Java-index,Archived Forums,Java Programming...
# 2
Post ur code
priviet at 2007-6-29 0:47:37 > top of Java-index,Archived Forums,Java Programming...
# 3
if you are putting the sentence into a href, enclose in double quotes.
mchan0 at 2007-6-29 0:47:37 > top of Java-index,Archived Forums,Java Programming...
# 4

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

amit_vj at 2007-6-29 0:47:37 > top of Java-index,Archived Forums,Java Programming...
# 5
try to givr it like thatvalue=""+ s15 +""if(fin != null){ht.load(fin);s15 = (String)ht.get("title");out.println(s15);//check it has full title or notfin.close();}
priviet at 2007-6-29 0:47:37 > top of Java-index,Archived Forums,Java Programming...
# 6
Like that value=\""+ s15 +"\"
priviet at 2007-6-29 0:47:37 > top of Java-index,Archived Forums,Java Programming...
# 7
hi there,out.println(si5); it displays whole sentence.and double codes are already there for concating it with html tags.
amit_vj at 2007-6-29 0:47:37 > top of Java-index,Archived Forums,Java Programming...
# 8
sorry friend,out.println(s15); is not whole title.system.out.print(s15); is a whole title on command prompt.
amit_vj at 2007-6-29 0:47:37 > top of Java-index,Archived Forums,Java Programming...