My bean doesn't APPEAR on my JSP page!  
Author Message
factor





PostPosted: 2003-8-24 9:35:00 Top

java-programmer, My bean doesn't APPEAR on my JSP page! Hi, All!

I have this simple bean (below), and i make the .class using JBuilder 7.0.

I tryed to insert this bean into my JSP page:

<%@ page contentType="text/html; charset=windows-1251" %>
<html>
<head>
<title>
Jsp1
</title>
</head>
<jsp:useBean id="bean0" scope="session" class="bean1.KivaHanTester" />
<jsp:setProperty name="bean0" property="*" />
<body>
<h1>
JBuilder Generated JSP
</h1>
</body>
</html>

BUT I CAN't see this bean, when i open my JSP (IExplorer + Apache).
May be i need to init this bean, like init() or show() i don't know.

Thanks.


SOURCE CODE:

package bean1;

import java.awt.*;

public class KivaHan extends Canvas {

private String msg;
private int width, height;

public KivaHan () {
this ("Coffee: 10 lira");
}
public KivaHan (String s) {
this (s, 200, 200);
}
public KivaHan (String s, int width, int height) {
msg = s;
this.width = width;
this.height = height;
setForeground (Color.cyan);
setFont (new Font ("Serif", Font.ITALIC, 24));
setSize (getPreferredSize());
}
public void paint (Graphics g) {
Dimension d = getSize();
FontMetrics fm = g.getFontMetrics();
int len = fm.stringWidth (msg);
int x = Math.max (((d.width - len) / 2), 0);
int y = d.height / 2;
g.drawString (msg, x, y);
}

public Dimension getPreferredSize () {
return new Dimension (width, height);
}
}

package bean1;

public class KivaHanTester extends java.applet.Applet {
public void init () {
add (new KivaHan());
}
}
 
G





PostPosted: 2003-8-24 17:30:00 Top

java-programmer >> My bean doesn't APPEAR on my JSP page! I think you are trying to see an Applet (your 'bean' is an applet) in
your JSP, but this is not the aim of a bean in a JSP...

If you want your applet to run into your browser you must use the HTML
<applet> tag.

Remember: JSP is server side, applet is client side.

Regards.

Kevin wrote:

> Hi, All!
>
> I have this simple bean (below), and i make the .class using JBuilder 7.0.
>
> I tryed to insert this bean into my JSP page:
>
> <%@ page contentType="text/html; charset=windows-1251" %>
> <html>
> <head>
> <title>
> Jsp1
> </title>
> </head>
> <jsp:useBean id="bean0" scope="session" class="bean1.KivaHanTester" />
> <jsp:setProperty name="bean0" property="*" />
> <body>
> <h1>
> JBuilder Generated JSP
> </h1>
> </body>
> </html>
>
> BUT I CAN't see this bean, when i open my JSP (IExplorer + Apache).
> May be i need to init this bean, like init() or show() i don't know.
>
> Thanks.
>
>
> SOURCE CODE:
>
> package bean1;
>
> import java.awt.*;
>
> public class KivaHan extends Canvas {
>
> private String msg;
> private int width, height;
>
> public KivaHan () {
> this ("Coffee: 10 lira");
> }
> public KivaHan (String s) {
> this (s, 200, 200);
> }
> public KivaHan (String s, int width, int height) {
> msg = s;
> this.width = width;
> this.height = height;
> setForeground (Color.cyan);
> setFont (new Font ("Serif", Font.ITALIC, 24));
> setSize (getPreferredSize());
> }
> public void paint (Graphics g) {
> Dimension d = getSize();
> FontMetrics fm = g.getFontMetrics();
> int len = fm.stringWidth (msg);
> int x = Math.max (((d.width - len) / 2), 0);
> int y = d.height / 2;
> g.drawString (msg, x, y);
> }
>
> public Dimension getPreferredSize () {
> return new Dimension (width, height);
> }
> }
>
> package bean1;
>
> public class KivaHanTester extends java.applet.Applet {
> public void init () {
> add (new KivaHan());
> }
> }