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.

Results 1 to 10 of 10

Thread: how to transform an html file to a web site in java

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default how to transform an html file to a web site in java

    I want to change an html code to an html webpage with java. how can I do it?


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: how to transform an html file to a web site in java

    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.

  3. #3
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: how to transform an html file to a web site in java

    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.

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to transform an html file to a web site in java

    ucl......?

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: how to transform an html file to a web site in java

    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

  6. #6
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: how to transform an html file to a web site in java

    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.

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: how to transform an html file to a web site in java

    nasi, try using the method getURL() from the File class to feed into the setPage function.
    java.net.URL [COLOR="SeaGreen"]helpURL[/COLOR] = file.getURL();//UpLoadListener.class.getResource( file.getPath());
    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.

    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.

  8. The Following User Says Thank You to copeg For This Useful Post:

    nasi (March 28th, 2010)

  9. #8
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: how to transform an html file to a web site in java

    thanks copeg, but the FILE class doesn't have getURL method, when I use file.getURL it generates an error.

  10. #9
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: how to transform an html file to a web site in java

    Quote Originally Posted by nasi View Post
    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();

  11. The Following User Says Thank You to copeg For This Useful Post:

    nasi (March 28th, 2010)

  12. #10
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: how to transform an html file to a web site in java

    Thank you very much copeg, hope you find some one to solve all of your problems

Similar Threads

  1. why does this code read an html file uncontinuously
    By nasi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 25th, 2010, 09:09 PM
  2. Implementing HTML tags in Java Source Code
    By bookface in forum Java Theory & Questions
    Replies: 4
    Last Post: March 19th, 2010, 09:29 PM
  3. Related to Html and Java Script?
    By JackyRock in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: February 17th, 2010, 03:10 AM
  4. Help with html tags in java
    By peliukasss in forum Member Introductions
    Replies: 0
    Last Post: February 2nd, 2010, 06:47 AM

Tags for this Thread