473,663 Members | 2,864 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it Posible to read text/html file in jsp ?

38 New Member
hi every one.
i am new to this forum.

i have two doubts.

one is , is it possible to read a text/html file in Jsp?

if so, how can we find out the end of each line in the text/html file?

please help me..

Thanks in Advance.
Nov 12 '08 #1
9 19088
r035198x
13,262 MVP
You can use Java code in JSPs so you can read any file the same way you would do it in your normal Java programs. The important thing to realize is that JSPs run on the server and so any paths you specify are relative to the server.
Nov 12 '08 #2
xtremebass
38 New Member
You can use Java code in JSPs so you can read any file the same way you would do it in your normal Java programs. The important thing to realize is that JSPs run on the server and so any paths you specify are relative to the server.

i have did coding like this,it shows error.. please do verify this reply for correct solution..

Expand|Select|Wrap|Line Numbers
  1. <%@ page import="java.io.*" %>
  2. <html>
  3. <head>
  4. <h2> Sample File Reading through Jsp </h2></head>
  5.  
  6. <%
  7. try
  8. {
  9.  
  10. BufferedReader input = new BufferedReader(new FileReader("mm.html"));
  11. String line = "";
  12. while ((line=input.readLine()) != null)
  13. {
  14.    out.println(line);
  15. }
  16. output.flush();
  17. input.close();
  18. }
  19. catch(Exception e)
  20. {
  21. out.println(e);
  22. }
  23. %>
  24. </html>
Nov 12 '08 #3
r035198x
13,262 MVP
1.) Please use code tags when posting code.
2.) What was the error message that you got.
3.) Your HTML page does not have a body?
Nov 12 '08 #4
xtremebass
38 New Member
1.) Please use code tags when posting code.
2.) What was the error message that you got.
3.) Your HTML page does not have a body?
thanks for reply. i will use code tags for next post,
and i have got an exception when
the browser was trying to display the text file.
the exception which was shown in my browser ,
"java.io.FileNo tFoundException : mm.html
(No such file or directory) " so where i have to
place my text file. so that i can avoid this problem. i am using linux os where i have installed apache -tomact server and i have placed both files that is jsp file,and html file in the same directory. so please be tell me where i was made a mistake?
could you not understand anything detaily means i will send a next post with detailed with all information. my main intention is to read a text file in jsp and display the contents in browser .. thats what i need it.
Nov 12 '08 #5
r035198x
13,262 MVP
You need to use the servlet context to get to that file's path, something like

Expand|Select|Wrap|Line Numbers
  1. URL url =config.getServletContext().getResource("mm.html");
  2. BufferedReader br =new BufferedReader(new InputStreamReader(url.openStream()));
Nov 12 '08 #6
xtremebass
38 New Member
You need to use the servlet context to get to that file's path, something like

Expand|Select|Wrap|Line Numbers
  1. URL url =config.getServletContext().getResource("mm.html");
  2. BufferedReader br =new BufferedReader(new InputStreamReader(url.openStream()));
when i am trying to post the new post the post cant be sent shows message like Below mentioned. i have typed lengthy message. i dont know why it message shows like that..

" 1. The message you have entered is too short. Please lengthen your message to at least 20 characters."
Nov 12 '08 #7
r035198x
13,262 MVP
Make sure your post exceeds 20 characters and is not inside quote tags. Just use the Post reply button at the bottom which doesn't include the usually unnecessary quote.
Nov 12 '08 #8
xtremebass
38 New Member
[quote] java.io.FileNot FoundException: mm.html (No such file or directory) [quote]

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ page import="java.io.*" %>
  3. <%@ page import="javax.servlet.ServletConfig.*" %>
  4. <%@ page import="javax.servlet.ServletContext.*" %>
  5. <%@ page import="javax.servlet.ServletException.*" %>
  6.  
  7.  
  8. <html>
  9. <head>
  10. <h2> Sample File Reading through Jsp </h2></head>
  11.  
  12. <%
  13. try
  14. {
  15.  
  16.  
  17. File file = new File("mm.html");
  18.  
  19.         InputStreamReader streamReader =
  20.                 new InputStreamReader(new FileInputStream(file));
  21.  
  22.         BufferedReader br = new BufferedReader(streamReader);
  23.  
  24.         String line = new String();
  25.         System.out.println(file.getName());
  26.         System.out.println("================");
  27.         while (br.ready()) {
  28.            line = br.readLine();
  29.             System.out.println(line);
  30.         }
  31.  
  32. }
  33. catch(Exception e)
  34. {
  35. out.println(e);
  36. }
  37. %>
  38.  
  39. </html>
  40.  
  41.  
Nov 12 '08 #9
r035198x
13,262 MVP
Did you see my reply #6?
Nov 12 '08 #10

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

Similar topics

1
9032
by: David Thomas | last post by:
Hi there, a while ago, I posted a question regarding reading japanese text from a text file. Well, since I solved the problem, I thought I'd post my solution for the benefit of other people with the same problem. The plan was to make a script to read and display japanese text. I will use it for making a japanese proverb script and for a japanese language study script.
3
74907
by: | last post by:
hey all, i wonder if it is posible to make a A:HOVER without a class defintion.. so <a href="#" style="{color:red;};HOVER{color:blue}">test</a> because i am sending html email in the body and the web interface filters out the classes..
3
7764
by: hunterb | last post by:
I have a file which has no BOM and contains mostly single byte chars. There are numerous double byte chars (Japanese) which appear throughout. I need to take the resulting Unicode and store it in a DB and display it onscreen. No matter which way I open the file, convert it to Unicode/leave it as is or what ever, I see all single bytes ok, but double bytes become 2 seperate single bytes. Surely there is an easy way to convert these mixed...
2
3289
by: Reply Via Newsgroup | last post by:
Folks, I'm pretty sure it can be done, and I'm doing pretty good with my javascript so I'm pretty sure I just need a quick point in the right direction... If my web page is referenced in the address bar, how can I read these arguements? Thus, with
1
4298
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each time after routine process A, the text file is named "mytext.dat" in following format with "#####" as separator. The maximum entries of them is 5. When reaching the fifth entry, it will delete the very first entry.
1
1773
by: Grzegorz ¦lusarek | last post by:
Hi All. One of the fields used in my form is to upload file, Is is to posible to made this field readonly and after filling radio field set this to use by javascript. I don't wanna give a User chance to upload file until he check in the form that he want's to upload File. thanks for any help Gregor
14
5755
by: Zoro | last post by:
My task is to read html files from disk and save them onto SQL Server database field. I have created an nvarchar(max) field to hold them. The problem is that some characters, particularly html entities, and French/German special characters are lost and/or replaced by a question mark. This is really frustrating. I have tried using StreamReader with ALL the encodings available and none work correctly. Each encoding handles some characters...
3
6241
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" ...
3
5390
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store that multiple worksheet data in different table.How can i do it.Below is my xml file. <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office"...
0
8436
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8858
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8634
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5657
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4182
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4349
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.