I want to change an html code to an html webpage with java. how can I do it?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I want to change an html code to an html webpage with java. how can I do it?
Hello nasi.
I have moved this thread to: Java Theory & Questions - Java Programming Forums
Please don't post in the 'Whats Wrong With My Code' forum unless you have an actual code problem to post.
Can you please elaborate on what you would like to do? I am a bit confused. Thanks.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputation by clicking the button on their useful posts.
sorry for that. I have read an html file and what I have now is its code. I have done some changes in the code, and now I want to change it to a web page to show to users. I don't want to display the codes of my html file, I want its web page form.
ucl......?
Unfortunately java SE lacks in this category. The JEditorPane has limited html capabilities, and there isn't another class in java SE that can do so. You'll have to a) use third party software such as The DJ project , or b) save the html as a file and open that file with the default web browser
Thank you copeg for your great helps. now I am trying to use EditorPane to work with my html file. I am trying to customize an EditorPane example of java tutorials for my application. I am using the following code but it doesn't find the html file, although it is there.
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("Uploading Lecture Notes")) {
int returnVal = fc.showOpenDialog(UpLoadListener.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
try {
java.net.URL URL = UpLoadListener.class.getResource( file.getPath());
if (URL != null) {
try {
note.setPage(helpURL);
} catch (IOException e1) {
System.err.println("Attempted to read a bad URL: " + helpURL);
}
} else {
System.err.println("Couldn't find file");
}
}
}
cheers
Last edited by nasi; March 28th, 2010 at 07:47 PM.
nasi, try using the method getURL() from the File class to feed into the setPage function.
The getResource finds a resource relative to the package and is more for loading things relative to your application, whereas it seems you wish to load something using the absolute path.java.net.URL [COLOR="SeaGreen"]helpURL[/COLOR] = file.getURL();//UpLoadListener.class.getResource( file.getPath());
Also note the name in green, which should be consistent with what you send to setPage. I'll also restate that the HTML of JEditorPane is limited. Anything beyond basic html (css, javascript, etc...) will most likely display incorrectly.
nasi (March 28th, 2010)
thanks copeg, but the FILE class doesn't have getURL method, when I use file.getURL it generates an error.
My bad...the correct syntax is toURL - which by chance is deprecated. (see File - toURL)). The work around is to convert to a URI then to a URL:
java.net.URL helpURL = file.toURI().toURL();
nasi (March 28th, 2010)
Thank you very much copeg, hope you find some one to solve all of your problems