applet的问题,急,解决立即送分,100

nb5411 2003-10-18 10:07:34
我在网页中嵌入applet还能正常显示,可是我把服务器启动后,通过网络就不能正常显示,原因是找不到那个applet类,我估计是codebase的问题,可是我怎么也设置不对。我用的是weblogic,我本来是做applet和servlet通信的,现在通过网络无法正常显示,很郁闷。请赐教。
...全文
51 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
noratong 2003-11-02
  • 打赏
  • 举报
回复
你能说说你这样作的意图吗????

一个简单的applet怎么被你搞的有点复杂呢,而且通过你的提问,我觉得你好像还没彻底搞清楚applet到底该用在什么地方呢。
nb5411 2003-11-02
  • 打赏
  • 举报
回复
谢谢以上各位,谢谢那位给我发消息的老兄。
SwordsmanF 2003-10-19
  • 打赏
  • 举报
回复
还有Applet里面如果有网络通信的代码。它只能与web服务器这台电脑通信,与其实主机似乎不允许
SwordsmanF 2003-10-19
  • 打赏
  • 举报
回复
你有没有将applet的类放到codebase所指的路径里呢
wangchq 2003-10-19
  • 打赏
  • 举报
回复
把你的codebase只向那个网络的连接。
比如你的类文件是test.MyTest.class,放在了网站的/applet/test/MyTest.class目录下,你的网站地址为http://www.mytest.com,则你要将你的codebase设置为http://www.mytest.com/applet,你的applet class="test.MyTest.class",注意,不要放在/WEB-INF下面,在那个下面,远程终端(客户端)是访问不到的。
nb5411 2003-10-19
  • 打赏
  • 举报
回复
谢谢各位的帮助,已经有所进展,远程能显示了,可是上面的按钮点击就没有用,也没有什么包错,我不懂为什么了,事件处理我用的是匿名类,编译后生成三个类文件,其中一个是APPLET的,一个是事件处理的匿名类,另外一个好象是什么备份,是不是我的类文件放位置不对,找不到,才没有响应的,请大家看看.服务器192.168.0.2

public class NetEcho extends Applet {
int turnOutput=0;
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JLabel jLabel2 = new JLabel();
JTextArea jTextArea1 = new JTextArea();
//Initialize the applet
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
jLabel1.setText("发送的数据");
jLabel1.setBounds(new Rectangle(49, 24, 61, 34));
this.setLayout(null);
jTextField1.setText("");
jTextField1.setBounds(new Rectangle(115, 29, 143, 26));
jButton1.setBounds(new Rectangle(278, 31, 75, 27));
jButton1.setText("发送");
jButton1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(jTextField1.getText().equals("")||jTextField1.getText()==null){
return;
}
try{
URL url=new URL("http://192.168.0.2:7001/servlet/NetEchoServlet");
URLConnection con=url.openConnection();
con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(false);
con.setRequestProperty("Content-type","application/octet-stream");
turnOutput+=1;
ByteArrayOutputStream byteOut=new ByteArrayOutputStream();
DataOutputStream out=new DataOutputStream(byteOut);
out.writeInt(turnOutput);
out.writeUTF(jTextField1.getText());
out.flush();
byte buf[]=byteOut.toByteArray();
con.setRequestProperty("Content-length",""+buf.length);
DataOutputStream buffOut=new DataOutputStream(con.getOutputStream());
buffOut.write(buf);
buffOut.flush();
buffOut.close();
DataInputStream in=new DataInputStream(con.getInputStream());
jTextArea1.append(in.readInt()+":"+in.readUTF()+"\n");
in.close();
}
catch(Exception ex){
ex.printStackTrace();
}

}

});
jLabel2.setText("接收的数据");
jLabel2.setVerticalAlignment(SwingConstants.CENTER);
jLabel2.setBounds(new Rectangle(150, 74, 61, 36));
jTextArea1.setBounds(new Rectangle(24, 140, 340, 157));
this.add(jTextField1, null);
this.add(jButton1, null);
this.add(jLabel1, null);
this.add(jLabel2, null);
this.add(jTextArea1, null);

}

}


package servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class NetEchoServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
public void service(HttpServletRequest req,HttpServletResponse res)throws IOException
{
res.setContentType("application/octet-stream");
DataInputStream in=new DataInputStream(req.getInputStream());
ByteArrayOutputStream byteOut=new ByteArrayOutputStream();
DataOutputStream out=new DataOutputStream(byteOut);
int i=in.readInt();
String j=in.readUTF();
out.writeInt(i);
out.writeUTF(j);
out.flush();
byte[] buff=byteOut.toByteArray();
res.setContentLength(buff.length);
ServletOutputStream httpOut=res.getOutputStream();
httpOut.write(buff);
httpOut.close();
}
//Clean up resources
public void destroy() {
}
}
LingFengNB 2003-10-19
  • 打赏
  • 举报
回复
up
yaray 2003-10-18
  • 打赏
  • 举报
回复
bu zhi dao.

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧