Обсуждение: Newbie question - Applet works only in appletviewer

Поиск
Список
Период
Сортировка

Newbie question - Applet works only in appletviewer

От
"Shmuel A. Kahn"
Дата:
Hello all, I just joined the list.

I am trying to write an applet for the internet, to display (output
only) some DB data. I managed to get my code to work as an application,
and even run under the appletviewer, but it fails under both Internet
Exploder 6. and Netscape 7.

What type of stuff would a newbie to Java like myself be overlooking?
Does my applet need to be made secure? Do I need to create a multi-tier
set-up for this?

Shmuel Kahn
--
You're just jealous because the voices only talk to me.
Shmuel A. Kahn
Shmuel@Kam-motion.com


Re: Newbie question - Applet works only in appletviewer

От
"Shmuel A. Kahn"
Дата:
> I am trying to write an applet for the internet, to display (output
> only) some DB data. I managed to get my code to work as an application,
> and even run under the appletviewer, but it fails under both Internet
> Exploder 6. and Netscape 7.

Woops!!
Forget to mention I am crashing on the following exceptions:

---------------------------------------------------
Error -- java.lang.ClassNotFoundException: org.postgresql.Driver
Error -- java.sql.SQLException: No suitable driver
Error -- java.lang.NullPointerException

Shmuel Kahn

--
You're just jealous because the voices only talk to me.
Shmuel A. Kahn
Shmuel@Kam-motion.com


Re: Newbie question - Applet works only in appletviewer

От
Sam Varshavchik
Дата:
Shmuel A. Kahn writes:

>> I am trying to write an applet for the internet, to display (output
>> only) some DB data. I managed to get my code to work as an application,
>> and even run under the appletviewer, but it fails under both Internet
>> Exploder 6. and Netscape 7.
>
> Woops!!
> Forget to mention I am crashing on the following exceptions:
>
> ---------------------------------------------------
> Error -- java.lang.ClassNotFoundException: org.postgresql.Driver
> Error -- java.sql.SQLException: No suitable driver
> Error -- java.lang.NullPointerException

Your browser's Java VM obviously does not have the PostgreSQL JDBC driver,
jdbc*.jar, installed.  Hence when the browser downloads your applet, and
runs it, the PostgreSQL JDBC driver is not available.

appletviewer reads your CLASSPATH, and pulls in the JDBC driver that way,
but this mechanism is obviously not available in a real browser.

There are several possible ways to fix this.  One is to insert jdbc*.jar
into your own applet's jar, so the browser ends up downloading both your
applet, and the JDBC driver.  Besides being a rather hefty download, this is
not going to work anyway unless the PostgreSQL database is on the same
server as your applet.  The browser's security manager will prevent the
application from logging in to any database not on the same server the
applet was loaded from.

A more common approach is to wrap all the database access code into a
separate class that's left on the server, and invoked via RMI.  This'll work
rather well, provided that the known issues with Sun's rmiregistry are
squared away, and sending data over the network in cleartext isn't an issue.


--
Sam


Re: Newbie question - Applet works only in appletviewer

От
"Shmuel A. Kahn"
Дата:
On 5 Jun 2002 at 16:29, Sam Varshavchik wrote:

Thank for your reply.

> Your browser's Java VM obviously does not have the PostgreSQL JDBC
> driver, jdbc*.jar, installed.  Hence when the browser downloads your
> applet, and runs it, the PostgreSQL JDBC driver is not available.
>
> appletviewer reads your CLASSPATH, and pulls in the JDBC driver that
> way, but this mechanism is obviously not available in a real browser.
>
> There are several possible ways to fix this.  One is to insert
> jdbc*.jar into your own applet's jar, so the browser ends up
> downloading both your applet, and the JDBC driver.

I tried this just to see if I could use quick-and-dirty for a temporary
solution, but couldn't get it to work. I tried all sorts of jar options
(including indexing), but no-go.

How is the VM supposed to know that the driver classes are within the
nested jar file? Am I missing something?

> Besides being a rather hefty download,
> this is not going to work anyway unless the PostgreSQL database is on
> the same server as your applet.  The browser's security manager will
> prevent the application from logging in to any database not on the
> same server the applet was loaded from.

At present I'm not using a web-server, just viewing a local file. This
specific DB is maintained for outputting the system data, I think the
DB will stay on the same machine for the foreseeable future.

> A more common approach is to wrap all the database access code into a
> separate class that's left on the server, and invoked via RMI.

Being a complete Java newbie, I am now looking into RMI. Any pointers?

To use RMI what type of SERVER set-up do I need? At present I don't
even an web-server on the "server" side, as everything "runs" on the
same machine.

TIA for any further comments and help.

Shmuel Kahn
--
You're just jealous because the voices only talk to me.
Shmuel A. Kahn
Shmuel@Kam-motion.com


Re: Newbie question - Applet works only in appletviewer

От
Richard Meester
Дата:
Hi Shmuel,

The problem is that you are not running a webserver, in normal situations you need to download a HTML file which incorporates the applet, and also an archive tag which says where the jar resides where the applet is located and how the JAR is named. So when you use an applet and use the jdbc driver, you need to include your applet and the driver in a JAR file, create an HTML file which tels the navigator/explorer where to find the code, and then run it.

We have had the same problems, we wanted to quickly see how the applet looked like (for an embedded logging tool that dumped its data into a database directly) in a navigator/explorer, but this doesn't work, because the explorer only nows where to find the applet, but not the rest. The explorer/navigator has no knowledge of CLASSPATH settings whatsoever. So the only remedy is to run a webserver, and create the html file and the jar files,

Hope this helps,

Richard

Shmuel A. Kahn wrote:
On 5 Jun 2002 at 16:29, Sam Varshavchik wrote:

Thank for your reply.

Your browser's Java VM obviously does not have the PostgreSQL JDBC
driver, jdbc*.jar, installed. Hence when the browser downloads your
applet, and runs it, the PostgreSQL JDBC driver is not available.

appletviewer reads your CLASSPATH, and pulls in the JDBC driver that
way, but this mechanism is obviously not available in a real browser.

There are several possible ways to fix this. One is to insert
jdbc*.jar into your own applet's jar, so the browser ends up
downloading both your applet, and the JDBC driver.

I tried this just to see if I could use quick-and-dirty for a temporary
solution, but couldn't get it to work. I tried all sorts of jar options
(including indexing), but no-go.

How is the VM supposed to know that the driver classes are within the
nested jar file? Am I missing something?

Besides being a rather hefty download,
this is not going to work anyway unless the PostgreSQL database is on
the same server as your applet. The browser's security manager will
prevent the application from logging in to any database not on the
same server the applet was loaded from.

At present I'm not using a web-server, just viewing a local file. This
specific DB is maintained for outputting the system data, I think the
DB will stay on the same machine for the foreseeable future.

A more common approach is to wrap all the database access code into a
separate class that's left on the server, and invoked via RMI.

Being a complete Java newbie, I am now looking into RMI. Any pointers?

To use RMI what type of SERVER set-up do I need? At present I don't
even an web-server on the "server" side, as everything "runs" on the
same machine.

TIA for any further comments and help.

Shmuel Kahn
--
You're just jealous because the voices only talk to me.
Shmuel A. Kahn
Shmuel@Kam-motion.com


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

.