当前位置: 代码迷 >> Java相关 >> 大家帮帮我啊,急!!!!,谢谢.
  详细解决方案

大家帮帮我啊,急!!!!,谢谢.

热度:146   发布时间:2005-09-26 20:16:00.0
大家帮帮我啊,急!!!!,谢谢.
写了一个留言板的程序,提交留言后,留言会保存在一个指定的文件中.
可是我把它改写成一个小应用程序后,在IE中时,提交留言不成功啊.据说是什么JAVA的安全特性.

谁能帮我具体的讲讲啊,,我会非常谢谢你的.
----------------解决方案--------------------------------------------------------
show code
----------------解决方案--------------------------------------------------------

这个不是代码问题吧 import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*;import java.applet.*; //姓名面板 class name extends JPanel {JLabel label; JTextField text; public void name() {label=new JLabel("姓名"); text=new JTextField(10); add(label);add(text); }} //性别面板 class sex extends JPanel {JLabel label; JComboBox choice; public void sex() {label=new JLabel("姓别"); String[] s={"男","女","不想说"}; choice=new JComboBox(s); add(label);add(choice); }} //用户看法面板 class advice extends JPanel {JLabel label; JRadioButton b1,b2,b3,b4; ButtonGroup group; public void advice() {label=new JLabel("你的看法"); b1=new JRadioButton("非常好");b2=new JRadioButton("很好"); b3=new JRadioButton("一般");b4=new JRadioButton("不好"); group=new ButtonGroup(); group.add(b1);group.add(b2);group.add(b3);group.add(b4); add(label);add(b1);add(b2);add(b3);add(b4); }} //用户议建区 class say extends JPanel {JLabel label; JTextArea text; public void say() {label=new JLabel("你填写你的议建"); text=new JTextArea(10,10); setLayout(new BorderLayout()); add(label,BorderLayout.NORTH); add(text,BorderLayout.SOUTH); }} //按钮区 class button extends JPanel {JButton button1,button2; void button() {button1=new JButton("确定"); button2=new JButton("取消"); add(button1);add(button2); }} //主功能主类 public class all extends JApplet implements ActionListener {say say1;name name1;button b; public void init() {//JFrame frame=new JFrame("留言板"); Container con=getContentPane(); JPanel panel=new JPanel();//主面板 panel.setBorder(BorderFactory.createTitledBorder("意见栏"));//设置主面板的标题 panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));//设置主面板的布局 name1=new name();name1.name(); sex sex1=new sex();sex1.sex(); advice advice1=new advice();advice1.advice(); say1=new say();say1.say(); b=new button();b.button(); panel.add(name1);panel.add(sex1);panel.add(advice1);panel.add(say1);panel.add(b); con.add(panel);

b.button1.addActionListener(this); b.button2.addActionListener(this);

//frame.pack(); //frame.addWindowListener(new WindowAdapter(){public void windowClosing//(WindowEvent e){System.exit(0);}}); //frame.show(); } public void actionPerformed(ActionEvent e) {String s; if(e.getSource()==b.button1) {s="用户姓名:"+name1.text.getText()+" "+"用户意见:"+say1.text.getText(); try { FileOutputStream chars=new FileOutputStream("msg.txt"); Writer out=new OutputStreamWriter(chars); out.write(s); out.close(); } catch(IOException ee) {System.out.println("文件打开错误");} } if(e.getSource()==b.button2) {say1.text.setText("");name1.text.setText("");}

}

}


----------------解决方案--------------------------------------------------------
qvbhsskg, 你的程序中有一些错误,改完后运行出现了 security exception 确实如你所说,applet 不可以读写客户端的文件的。通常的IO 对 applet 来讲就没用了。 下面是JavaTutorial 上面的介绍,你有兴趣的话,可以看看 http://java.sun.com/docs/books/tutorial/applet/practical/security 需要注意的是,applet 程序是可以访问服务器端的资源的。也就是说,你把你的本地机器作为一个服务器,那么至少可以访问你自己的机器。applet 也可以互相间访问。 点击下面的连接,有关于服务器端的程序的介绍。 http://java.sun.com/docs/books/tutorial/applet/practical/server
----------------解决方案--------------------------------------------------------
  相关解决方案