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.
9 19088
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.
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.. - <%@ page import="java.io.*" %>
-
<html>
-
<head>
-
<h2> Sample File Reading through Jsp </h2></head>
-
-
<%
-
try
-
{
-
-
BufferedReader input = new BufferedReader(new FileReader("mm.html"));
-
String line = "";
-
while ((line=input.readLine()) != null)
-
{
-
out.println(line);
-
}
-
output.flush();
-
input.close();
-
}
-
catch(Exception e)
-
{
-
out.println(e);
-
}
-
%>
-
</html>
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?
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.
You need to use the servlet context to get to that file's path, something like - URL url =config.getServletContext().getResource("mm.html");
-
BufferedReader br =new BufferedReader(new InputStreamReader(url.openStream()));
You need to use the servlet context to get to that file's path, something like - URL url =config.getServletContext().getResource("mm.html");
-
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."
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.
[quote] java.io.FileNot FoundException: mm.html (No such file or directory) [quote] -
-
<%@ page import="java.io.*" %>
-
<%@ page import="javax.servlet.ServletConfig.*" %>
-
<%@ page import="javax.servlet.ServletContext.*" %>
-
<%@ page import="javax.servlet.ServletException.*" %>
-
-
-
<html>
-
<head>
-
<h2> Sample File Reading through Jsp </h2></head>
-
-
<%
-
try
-
{
-
-
-
File file = new File("mm.html");
-
-
InputStreamReader streamReader =
-
new InputStreamReader(new FileInputStream(file));
-
-
BufferedReader br = new BufferedReader(streamReader);
-
-
String line = new String();
-
System.out.println(file.getName());
-
System.out.println("================");
-
while (br.ready()) {
-
line = br.readLine();
-
System.out.println(line);
-
}
-
-
}
-
catch(Exception e)
-
{
-
out.println(e);
-
}
-
%>
-
-
</html>
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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..
|
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...
|
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
|
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.
| |
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
|
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...
|
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"
...
|
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"...
|
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...
|
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...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |