Javascript刷新页面的几种方法:
10年积累的成都网站设计、成都做网站、外贸网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计后付款的网站建设流程,更有凤山免费网站建设让你可以放心的选择与我们合作。
复制代码代码如下:
1,history.go(0)
2,location.reload()
3,location=location
4,location.assign(location)
5,document.execCommand('Refresh')
6,window.navigate(location)
7,location.replace(location)
8,document.URL=location.href
哪个都行,第二个就可以试试,写在js里
如果是让那个内容添加到数据库后就全部消失的话。可以这样比如说我有个文本框private JTextFiled jt = new JTextFiled(); jt.setText("123456");然后等这个添加到数据库后在设置jt.setText("");这样所添加的内容就消失了。。也像刷新了
while (rs.next()) {
rowData[i][0] = rs.getString("exam_No");
rowData[i][1] = rs.getString("student_ID");
rowData[i][2] = rs.getString("student_Name");
rowData[i][3] = rs.getString("class_NO");
rowData[i][4] = rs.getString("course_Name");
rowData[i][5] = rs.getString("result");
i++;
}
//在此处添加如下代码:
xxxxxxxxxxxx_model.fireTableDataChanged();
//或:
table.setModel(new XxxxxxxxxxTableModel(rowData,.......));
解决方法1:
如果你的表格模型扩展自AbstractTableModel,
表格数据改变后,则调用模型的fireTableDataChanged()方法;
解决方法2:
重新设置表格模型.
例如:
table.setModel(new DefaultTableModel(data,columnNames));
下面是我写的一个上例子.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class JTableTest
{
public static void main(String args[])
{
JTableTestFrame f=new JTableTestFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class JTableTestFrame extends JFrame
{
private JTable table=null;
private ArrayTableModel atm=null;
private JButton reload=null;
private final static String[] columnNames={"Number","addend","augend","sum"};
private int start=0;
public JTableTestFrame()
{
atm=new ArrayTableModel(columnNames);
table=new JTable(atm);
reload=new JButton("Reload");
reload.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
reload();
}
});
JPanel p=new JPanel(new BorderLayout());
p.add(new JLabel("JTable Test"),BorderLayout.NORTH);
p.add(new JScrollPane(table),BorderLayout.CENTER);
p.add(reload,BorderLayout.SOUTH);
this.add(p);
this.setSize(300,300);
this.setVisible(true);
}
public void reload()
{
int rows=10;
int cols=columnNames.length;
Object[][] data=new Object[rows][cols];
for(int i=0;irows;i++)
{
start+=i;
data[i][0]=start;
data[i][1]=start+1;
data[i][2]=start+2;
data[i][3]=start*2+3;
}
atm.setData(data);
atm.fireTableDataChanged();
}
}
class ArrayTableModel extends AbstractTableModel
{
private String[] columnNames=null;
private Object[][] data=null;
public ArrayTableModel(String[] columnNames)
{
this.columnNames=columnNames;
this.data=new Object[1][columnNames.length];
}
public ArrayTableModel(Object[][] data,String[] columnNames)
{
this.data=data;
this.columnNames=columnNames;
}
public Object getValueAt(int r,int c)
{
return this.data[r][c];
}
public int getRowCount()
{
return this.data.length;
}
public int getColumnCount()
{
return this.columnNames.length;
}
public String[] getColumnNames() {
return columnNames;
}
public String getColumnName(int c)
{
return this.columnNames[c].toString();
}
public void setColumnNames(String[] columnNames) {
this.columnNames = columnNames;
}
public Object[][] getData() {
return data;
}
public void setData(Object[][] data) {
this.data = data;
}
}
让主界面刷新,你可以调用的主窗体的paintAll方法,
很多时候都吧,update().repaint().paintComponents()这些方法一起使用,
这里面的writer.flush();方法是刷新的意思不知道是不是你想要的。
public
class
Io
{
public
static
void
main
(String
[]
args)throws
Exception{
File
f=new
File(args[0]);
f.createNewFile();
new
File("test1").mkdir();
//
make
new
dir
File
f2=new
File("test1"
+
File.separator
+args[0]);
f2.createNewFile();
System.out.println(f2.getName());
System.out.println("
Absolute
Path
is:
"
+
f2.getAbsolutePath());
System.out.println("
Can
Read
:?
"
+
f2.canRead());
f2.renameTo(new
File("test"
+
File.separator+
"newfile"));
Io
i=new
Io();
i.writeOneLine(args[0]+".csv","测试,ghmn,你们,\nafd,asdf,\neee");}
public
void
writeOneLine(String
name,String
line){
PrintWriter
writer
=
null;
try
{writer
=
new
PrintWriter(new
FileWriter(name,
true));
writer.println(line);
writer.flush();
}
catch
(IOException
e)
{
System.out.println("Error:
"
+
e);}
finally
{
writer.close();}
}