I want to change an html code to an html webpage with java. how can I do it?
Printable View
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.
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
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.Code :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.
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:
Code :java.net.URL helpURL = file.toURI().toURL();
Thank you very much copeg, hope you find some one to solve all of your problems:)