How to run applet in a web Browser?
We are trying to execute the applet using web browser, while we are executed by the appletviewer it is working fine and is connecting the database and getting printing the values of the table in the applet. But when we tried to execute the same using web browser it is not. Please reply with solution asap.
Re: How to run applet in a web Browser?
Can you show me that how did you run your applet on the web browser? How did you integrate?
Re: How to run applet in a web Browser?
Below code is executed by c:\>appletviewer login.html is working properly it is giving database values as phone number and name.
In web browser in the address bar : c:\login.html when i hit this address it is giving background color page with labels and phone number as "0" and name as "null".
//login.java file
import java.awt.*;
import java.applet.*;
import java.sql.*;
/**
* Class login - write a description of the class here
*
* @author (your name)
* @version (a version number)
*/
public class login extends Applet
{ int ph;
String adr;
// instance variables - replace the example below with your own
Connection con;
Statement st;
ResultSet rs;
public void init()
{
setBackground(Color.pink);
display();
// provide any initialisation necessary for your JApplet
}
public void display()
{
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:tee");
st=con.createStatement();
rs=st.executeQuery("select * from info");
while(rs.next())
{
adr=rs.getString("Name");
ph=rs.getInt("Teleno");
repaint();
}
}
catch(Exception e)
{
System.out.println("Exception:"+e);
}
}
/**
* Paint method for applet.
*
* @param g the Graphics object for this applet
*/
public void paint(Graphics g)
{
// simple text displayed on applet
//g.setBackground(Color.pink);
//g.setColor(Color.black);
g.setColor(Color.black);
g.drawString("phone_no="+ph,20, 20);
// g.setColor(Color.blue);
g.drawString("Address="+adr,30, 40);
}
}
login.html
<html>
<body>
<applet code="login.class" width=700 height=700>
</applet>
</body>
</html>
Re: How to run applet in a web Browser?
By grant the permission of the sun.jdbc.odbc read permission that problem has been solved, now I am able to see the applet in web browser with database field values.
I have one question, I am doing one project based on applets on a single machine.In that I would like to protect each applet by embedding code in each applet, something like reading a parameter and if its value is null then it will take me to login page. For this modification any one have thoughts about this please reply back.
Re: How to run applet in a web Browser?
you have to make an HTML file for that,for your case,it's like-
<html>
<applet code="here comes the name of the .class file that contains your code" height =800 width=800>
<param name="parametername that you want to pass to applet" value=the value that is passed to applet >
</applet>
</htm>
save this file using .html extension and save it in the same folder that contains your .class file.......then open the .html file using web browser and bravo!!!!