
To create a simple web page that loads and runs a Java applet, you will need to follow these steps:
Create a new HTML file using a text editor or web development tool
Add the following code to the <head> section of the HTML file:
This will include the necessary JavaScript file that will enable the web page to load and run the Java applet
Add an <applet> element to the <body> section of the HTML file, using the following code as a template:
Replace "AppletClassName" with the name of the Java applet class that you want to run Adjust the width and height attributes to set the size of the applet on the web page
Save the HTML file and open it in a web browser that has Java installed and enabled The applet should load and run on the web page
It is worth noting that Java applets are not commonly used in modern web development, as they have been replaced by other technologies such as JavaScript and HTML5 However, if you need to run a Java applet on a web page, the steps above should help you to do so
首先静态的html标签是无法直接调用java程序的。
下面是实现的几种方法:
第一种方法:
将按钮放到form表单中,当按钮点击时提交表单(或者直接将input的type属性定义成submit),表单可以指向JSP或Servlet,在JSP或Servlet里调用java程序
第二种方法:
在按钮的onclick时间中添加js代码
selflocation="url";其中url指向JSP或Servlet
第三种方法:
使用第三方的javascript包,dwr是一个不错的选择:
1、需要准备dwr的jar包,并将之放到lib目录下;
2、修改webxml文件,添加DWRServlet的映射;
3、配置dwr,即在WEB-INF目录下,添加dwrxml文件,让dwr知道在运行时给哪些JavaBean生成相应的javascript库;
4、将需要的脚本库引入到html页面中就可以通过dwr的API访问java类了。
第四种方法:
使用MVC框架更简单,以struts为例,可以仿照第一或第二种方法,将url替换成配置文件中配置的地址就能访问java程序了。
新建个工程
一般我们用两类工程: 一个是 java工程 一个是web工程;
我们现在建的是java工程:
点右键
选择new
选择 project
选择 java project
Next
输入项目的名字(最好用英文或者拼音)
Finish
提示 是否打开
Yes
Ok 项目建成了 名字为 test
下面建一个类
在src 下面点右键
New
选 class(类)
输入类的名字(类开头名字一定要大写,并且最好是英文或则拼音)
将 main 选择
Finish
public class test {
/
@param args
/
public static void main(String[] args) {
//在这里 写代码
}
}
写个一个非常简单的代码
public class test {
/
@param args
/
public static void main(String[] args) {
//在这里 写代码
Systemoutprintln("你好");//
}
}
下面是加的代码
Systemoutprintln("你好");
怎么运行呢
点右键
选择 Run as
选择 java applications
运行结果如下
在这里打出来字了
主要是Class类:
class Class {
private String classId;
private Student[] list;
Class() {
}
Class(String classId, Student[] list) {
thisclassId = classId;
thislist = list;
}
String getClassId() {
return thisclassId;
}
int getNumber() {
return thislistlength;
}
int getFemaleNumber() {
int num = 0;
int i = 0;
while (i < thislistlength) {
if (thislist[i]getxingbie() == 'F') {
num++;
}
i++;
}
return num;
}
/```````````````````````````````````````````````````````````/
public static void main(String[] args) {
Name me = new Name();
mesetxing("黄");
mesetming("夏明");
Systemoutprintln("名字:" + megetxing() + megetming());
Systemoutprintln("测试getxing:" + megetxing());
Systemoutprintln("测试getming:" + megetming());
// Student Edison = new Student("huangxiaming", "a", '男');
Student Edison = new Student(me, "a", '男');//传参不对。只有Student(Name a, String b, char c),没有Student(String a, String b, char c)
Systemoutprintln(EdisontoString());
Systemoutprintln("姓名:" + EdisongetName());
Systemoutprintln("setName" + EdisongetName());
Systemoutprintln("学号:" + Edisongetxuehao());
Systemoutprintln("sex:" + Edisongetxingbie());
}
}//少了个大括号
我使用过两种解决方案解决这个问题。
首先不能用插件,那我们想使用QQ啊,MSN之类的完成客服就行不通。
方案一就是采用网页聊天的形式。客服人员和客户分别在不同的网页上及时交流。使用Ajax技术,当某一方发出消息之后,通过js脚本监视该应用端页面的输入端,将发出的消息发送给服务器,服务器将消息处理之后发送给另一方,另一方接受到消息之后局部页面刷新,将消息显示出来。
方案二,做一个Applet小程序实现TCP/IP通信,将这个程序嵌入到网页中,用户需要客服的时候运行Applet小程序就可以了。
以上就是关于怎样编写加载运行java applet的简单网页全部的内容,包括:怎样编写加载运行java applet的简单网页、如java小程序在html网页中怎么运行、如何使用eclipse创建项目及编写小程序实等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)