From: mpoisson Title: "Java Bean Browser" Points: 40
Answer Grade: A Date: Wednesday, March 15 2000 - 08:44PM PHT
I am writing an Java application that I would like to display html and jsp pages within a JPanel. Does anyone know if a bean exists to do this and where I can get it?
Question History
Comment
From: jerch
Date: Wednesday, March 15 2000 - 07:55PM PHT
Use JEditorPane. It supports HTML 3.2
JEditorPane1 htmlPane = new JEditorPane();
htmlPane.setName("My HTML Pane");
htmlPane.setBounds(0, 0, 400, 400);
htmlPane.setEditable(false);
htmlPane.setPage(<url>);
The setPage() method can either accept URL or String.
sincerely yours
Jerson
Comment
From: jerch
Date: Wednesday, March 15 2000 - 08:01PM PHT
By the away add it in a JScrollPane.
scrollPane.setViewportView(htmlPane);
Comment
From: mpoisson
Date: Wednesday, March 15 2000 - 10:51PM PHT
Can this htmlPane also display JSP(Java Server Pages)?
Comment
From: jerch
Date: Wednesday, March 15 2000 - 10:58PM PHT
Definitely, since jsp generates html. The jsp code is not actually returned. Likewise, it supports ASP. The important thing is that the page generated only contains html 3.2 tags. Otherwise, it will not be able to display or display properly the page.
Jerson
Comment
From: mpoisson
Date: Wednesday, March 15 2000 - 11:01PM PHT
Can this htmlPane also display JSP(Java Server Pages)?
Comment
From: mpoisson
Date: Thursday, March 16 2000 - 01:23AM PHT
I have tried this out, and it there seems to be some problems using forms. A submit button generates a null pointer exception coming from the java package javax.swing.text.html.FormView. I am not familiar with the EditorPane are we asking too much of it?
Comment
From: mpoisson
Date: Thursday, March 16 2000 - 01:59AM PHT
I have tried this out, and it there seems to be some problems using forms. A submit button generates a null pointer exception coming from the java package javax.swing.text.html.FormView. I am not familiar with the EditorPane are we asking too much of it?
Comment
From: mpoisson
Date: Thursday, March 16 2000 - 02:00AM PHT
Adjusted points from 200 to 400
Accepted Answer
From: jerch
Date: Thursday, March 16 2000 - 08:55AM PHT
Hello there... No you're not asking to much. It's actually because we have different time zone. :-) Your last post here was actually 2am here.
Anyway, I prepared a code for you. Check this out. This is the code for the html and make sure that you have all the syntax correct since I've tried it out and it supports form submission. It will throw exception if it encounters unrecognized tags or wrong syntax such as having <\body> instead of slash you have back slash.
So if I were able to make it work in servlet. It suppose to work with JSP. Since the JEditorPane does not care what server side program processes the form.
And this is the last program that you use to view the HTML
Answer Grade: A Date: Wednesday, March 15 2000 - 08:44PM PHT
I am writing an Java application that I would like to display html and jsp pages within a JPanel. Does anyone know if a bean exists to do this and where I can get it?
Accepted Answer
From: jerch
Date: Thursday, March 16 2000 - 08:55AM PHT
Text below...
Question History
Comment
From: jerch
Date: Wednesday, March 15 2000 - 07:55PM PHT
Use JEditorPane. It supports HTML 3.2
JEditorPane1 htmlPane = new JEditorPane();
htmlPane.setName("My HTML Pane");
htmlPane.setBounds(0, 0, 400, 400);
htmlPane.setEditable(false
htmlPane.setPage(<url>);
The setPage() method can either accept URL or String.
sincerely yours
Jerson
Comment
From: jerch
Date: Wednesday, March 15 2000 - 08:01PM PHT
By the away add it in a JScrollPane.
scrollPane.setViewportView
Comment
From: mpoisson
Date: Wednesday, March 15 2000 - 10:51PM PHT
Can this htmlPane also display JSP(Java Server Pages)?
Comment
From: jerch
Date: Wednesday, March 15 2000 - 10:58PM PHT
Definitely, since jsp generates html. The jsp code is not actually returned. Likewise, it supports ASP. The important thing is that the page generated only contains html 3.2 tags. Otherwise, it will not be able to display or display properly the page.
Jerson
Comment
From: mpoisson
Date: Wednesday, March 15 2000 - 11:01PM PHT
Can this htmlPane also display JSP(Java Server Pages)?
Comment
From: mpoisson
Date: Thursday, March 16 2000 - 01:23AM PHT
I have tried this out, and it there seems to be some problems using forms. A submit button generates a null pointer exception coming from the java package javax.swing.text.html.Form
Comment
From: mpoisson
Date: Thursday, March 16 2000 - 01:59AM PHT
I have tried this out, and it there seems to be some problems using forms. A submit button generates a null pointer exception coming from the java package javax.swing.text.html.Form
Comment
From: mpoisson
Date: Thursday, March 16 2000 - 02:00AM PHT
Adjusted points from 200 to 400
Accepted Answer
From: jerch
Date: Thursday, March 16 2000 - 08:55AM PHT
Hello there... No you're not asking to much. It's actually because we have different time zone. :-) Your last post here was actually 2am here.
Anyway, I prepared a code for you. Check this out. This is the code for the html and make sure that you have all the syntax correct since I've tried it out and it supports form submission. It will throw exception if it encounters unrecognized tags or wrong syntax such as having <\body> instead of slash you have back slash.
<html>
<body>
<b>Please Log in</b><br>
<form action="/servlet/Login" method="post">
Username: <input type="text" name="username" size="20"><BR>
Password: <input type="password" name="password" size="20"><BR>
<input type="submit" value="Log me in!">
</form>
</body>
</html>
On the other hand, this is servlet that the form submits to.
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Login extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
PrintWriter out = res.getWriter();
out.println("Username:&nbs
out.println("Password:&nbs
out.close();
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
doPost(req, res);
}
}
So if I were able to make it work in servlet. It suppose to work with JSP. Since the JEditorPane does not care what server side program processes the form.
And this is the last program that you use to view the HTML
import javax.swing.*;
import java.net.*;
import java.io.*;
class HTML {
public HTML(String url) throws IOException {
JEditorPane htmlPane = new JEditorPane();
htmlPane.setName("My HTML Pane");
htmlPane.setEditable(false
htmlPane.setPage(url);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setName("scroll
scrollPane.setBounds(0, 0, 640, 480);
scrollPane.setViewportView
JPanel panel = new JPanel();
panel.setName("panel");
panel.setLayout(null);
panel.add(scrollPane, scrollPane.getName());
panel.add(new JButton("OK"), "button");
JFrame frame = new JFrame();
frame.setName("HTML");
frame.setBounds(0, 0, 640, 480);
frame.setTitle("HTML");
frame.setContentPane(panel
//frame.setResizable(false
//frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) throws Exception {
HTML html = new HTML("http://localhost/");
}
}
Hope this helped.
Sincerely yours,
Jerson