loginFrame = new JFrame("登陆"); loginPanel = new JPanel(); usernamePanel = new JPanel(); passwordPanel = new JPanel(); buttonPanel = new JPanel(); usernameField = new JTextField(15); passwordField = new JTextField(15); usernameLabel = new JLabel("用户"); passwordLabel = new JLabel("密码"); submit = new JButton("登陆"); cancel = new JButton("重置");
if(登录成功)
{
out.print("欢迎xxx");
}
如在登录页面的话是login.jsp
有<input type="text" value="用户名" id="Username">
那么你可以在提交的时候用传址的方法,把他传到登录后的页面里
如var name=document.getElementById("Username");来获取值,在用
window.location.replace("a.jsp?Name="+name);的方式来传递参数
那么你在提交到另一个页面时,就可以用服务器语言来获取这个值
如String Name=request.getParameter("Name");来获取登录名
接着你就可以把他输出了,如用alert("<%=Name%>");就可以输出登录名
import java.awt.*;
import java.awt.event.*;public class LoginFrame { private JFrame loginFrame = null;
private JPanel loginPanel = null;
private JPanel usernamePanel = null;
private JPanel passwordPanel = null;
private JPanel buttonPanel = null;
private JTextField usernameField = null;
private JTextField passwordField = null;
private JLabel usernameLabel = null;
private JLabel passwordLabel = null;
private JButton submit = null;
private JButton cancel = null;
private void init() {
loginFrame = new JFrame("登陆");
loginPanel = new JPanel();
usernamePanel = new JPanel();
passwordPanel = new JPanel();
buttonPanel = new JPanel();
usernameField = new JTextField(15);
passwordField = new JTextField(15);
usernameLabel = new JLabel("用户");
passwordLabel = new JLabel("密码");
submit = new JButton("登陆");
cancel = new JButton("重置");
loginFrame.setLayout(new GridLayout(3,1));
loginFrame.add(usernamePanel);
loginFrame.add(passwordPanel);
loginFrame.add(buttonPanel);
usernamePanel.add(usernameLabel);
usernamePanel.add(usernameField);
passwordPanel.add(passwordLabel);
passwordPanel.add(passwordField);
buttonPanel.add(submit);
buttonPanel.add(cancel);
submit.addActionListener(new ButtonListener());
cancel.addActionListener(new ButtonListener());
loginFrame.pack();
loginFrame.setLocation(400, 300);
loginFrame.setVisible(true);
loginFrame.setAlwaysOnTop(true);
}
private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) {
String command = event.getActionCommand();
if("登陆".equals(command)) {
new MainFrame().init(usernameField.getText());
loginFrame.setVisible(false);
}
else if("重置".equals(command)) {
usernameField.setText("");
passwordField.setText("");
}
}
}
public static void main(String[] args) {
new LoginFrame().init();
}
}=========================================下面这个类是首页类,即你需要显示用户名的面板。=========================================import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class MainFrame {
private JFrame mainFrame = null;
private JPanel mainPanel = null;
private JLabel usernameLabel = null;
private JLabel usernameResult = null;
public void init(String username) {
mainFrame = new JFrame("首页");
mainPanel = new JPanel();
usernameLabel = new JLabel("当前登录用户为:");
usernameResult = new JLabel(username);
mainFrame.add(mainPanel);
mainPanel.add(usernameLabel);
mainPanel.add(usernameResult);
//----------------------
//这里定义其他需要在首页上需要显示的组件,这里我之定义了只要显示的用户名
//----------------------
mainFrame.pack();
mainFrame.setLocation(400, 300);
mainFrame.setVisible(true);
mainFrame.setAlwaysOnTop(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
=============================================