2024-05-29 06:29:34 | 我爱编程网
你可以在servlet中把你要知道的信息存到session中,ServletActionContext.getRequest().getSession().setAttribute("message", "程序正在组织数据,请稍后。。。。
HttpSession session=ServletActionContext.getRequest().getSession();
@SuppressWarnings("unused")我爱编程网
String str=(String)session.getAttribute("message");
需要知道什么消息酒吧消息项上面那样存储就可以了,然后在jsp中用${message}来取得session中的值,这样就可以动态的显示信息了!
你好,很高兴为你解答,以下答案来自问问团队:54666
=======================================================
你可以使用流来将运行结果写进一个文本文档中,请看我的如下的代码:
import java.io.*;
public class IOTest{public static void main(String[] args){PrintStream ps=null;try{FileOutputStream fos=new FileOutputStream("c:\\Test.txt");
如果只是一些文本要显示,可以在上面加个JTextArea,JTextField之类的组件,用这些组件的对象调用setText(" ")方法(括号里是字符串)来显示文本
比如:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
/** 文本区域
*
* @author Administrator
*
*/
public class TextArea extends JFrame {
private static final long serialVersionUID = 2306597749734227012L;
private JButton b1 = new JButton("Add Data"), b2 = new JButton("Clear Data");
private JTextArea text = new JTextArea(20, 40);
private Map
new HashMap
public TextArea() {
// Use up all the data:
map.put("a", "1");
map.put("b", "2");
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
for(@SuppressWarnings("rawtypes") Map.Entry me : map.entrySet()){
text.append(me.getKey()+": "+me.getValue()+"\n");
}
}
});
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
text.setText("");
}
});
setLayout(new FlowLayout());
add(new JScrollPane(text));
add(b1);
add(b2);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
GUItools.SwingConsole.run(new TextArea(), 475, 475);
}
}
JTextField和这差不多,只不过是显示单行的。
如果要显示其他字体的,可以用HTML格式,如下:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
/** Swing 组件上的HTML
*
* @author Administrator
*
*/
@SuppressWarnings("serial")
public class HTMLButton extends JFrame {
private JButton b = new JButton(
""+
"
// 必须使文本以 "" 标记开始。
public HTMLButton() {
// TODO Auto-generated constructor stub
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
add(new JLabel(""+"Kapow!"));
// Force a re-layout to include the new label:
validate();
}
});
setLayout(new FlowLayout());
add(b);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
GUItools.SwingConsole.run(new HTMLButton(), 200, 500);
}
}
2024-04-13 00:38:12
2024-03-31 15:14:06
2024-03-21 00:22:13
2024-02-10 22:15:59
2023-12-26 22:10:45
2023-10-06 13:00:52