老师要求编写JAVA的程序,实现登录界面功能的完善。

就是编写登录界面,并且把它包含的功能编写进去,你能帮我吗·?

第1个回答  2011-11-27
登录页面的代码为:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" import="s2jsp.bbs.dao.*,s2jsp.bbs.dao.Impl.*,java.util.*,s2jsp.bbs.entity.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>青鸟学员论坛--帖子列表</title>
<script language="javascript" >
function checklogin(){
if(checkUserName()&&checkPwd()){
return true;
}else{
return false;
}
}
function checkUserName(){
var userName=document.getElementById("txtUserName");
if(userName.value==""){
alert("请输入用户名!");
userName.select();
return false;
}
return true;
}
</script>
<link href="../CSS/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div class=" main w">
<%@ include file="../html/head.html" %>
<div class="menu w"><span><a href="index.jsp">论坛首页</a> >> 登录页面</span></div>
<div class="regL w">
<div class=" forL"><form action="admin/doLogin.jsp" method="post" id="myform" onsubmit="return checklogin()">
<div class="userL">用户名</div>
<div class="inpL" >
<input name="txtUserName" type="text" id="txtUserName" size="23" />
</div>
<div style="float:left; width:250px">
<div class="userL">密码</div>
<div class="inpL">
<input name="txtPwd" type="password" id="txtPwd" size="25" />
</div>
</div>
<div class="loginL"><input name="" type="submit" value="登 录" /></div>
</form>
</div>
</div><!--reg end-->
<%@ include file="../html/foot.html" %>
</div><!--mian end-->

</body>
</html>

登录页处理页面为:
<%@ page language="java" import="s2jsp.bbs.dao.*,s2jsp.bbs.dao.Impl.*,java.util.*,s2jsp.bbs.entity.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String userName=request.getParameter("txtUserName");
String pwd=request.getParameter("txtPwd");
UserDao userDao=new UserDaoImpl();
User user=userDao.findUser(userName);
if(user.getUPass().equals(pwd)){
session.setAttribute("name",user);
List loginList=new ArrayList();
//获取原有登录用户的信息
if(application.getAttribute("loginUser")!=null){
loginList=(List)application.getAttribute("loginUser");
}
boolean t=true;
for(int i=0;i<loginList.size();i++){
if(userName.equals(loginList.get(i).toString())){
t=false;
break;
}
}
//把新登陆的用户信息添加到列表中
if(t){
loginList.add(userName);
}
//把信息存入到全局范围内
application.setAttribute("loginUser",loginList);
response.sendRedirect("../index.jsp");
}else{
response.sendRedirect("../login.jsp");
}
%>
第2个回答  2011-11-27
不知道这个可不可以帮你。
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
public class Zidongjiayi extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
Button b1;
Button b2;
TextField L1;
boolean start=false;
public Zidongjiayi(){
this.setTitle("自动加一程序");
this.setSize(400,300);
this.setBackground(Color.lightGray);
int width=Toolkit.getDefaultToolkit().getScreenSize().width;
int height=Toolkit.getDefaultToolkit().getScreenSize().height;
this.setLocation((width-400)/2,(height-300)/2);
this.setResizable(false);
this.setLayout(new FlowLayout(1,20,50));
L1=new TextField("1",30);
L1.setSize(150, 10);
L1.setFont(new Font("宋体",0,16));
L1.setForeground(Color.red);
this.add( L1);
b1=new Button("自动加一");
b1.setSize(100, 10);
b1.setFont(new Font("宋体",0,16));
b1.setForeground(Color.blue);
this.add(b1);
b1.addActionListener(this);
b2=new Button("重 置");
b2.setSize(100, 10);
b2.setFont(new Font("楷体",0,16));
b2.setForeground(Color.blue);
this.add(b2);
b2.addActionListener(this);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1){
String str=L1.getText();
int i=Integer.parseInt(str);
L1.setText(String.valueOf(++i));
}
if(e.getSource()==b2){
L1.setText("1");
}
}
}
class Zidongjiayi_ex{
public static void main(String[] args) {
new Zidongjiayi();
}
}
第3个回答  2011-11-28
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
//默认的用户名和密码都是admin
public class UserLogin extends JFrame{
private static final long serialVersionUID = 1L;
private JLabel l_name,l_pass;
private JTextField t_name;
private JPasswordField t_pass;
private JButton submit,reset;
private JPanel pan;

public UserLogin(){
init();
}
private void init(){
l_name = new JLabel("用户名:");
l_pass = new JLabel("密 码:");
t_name = new JTextField(15);
t_pass = new JPasswordField(15);
submit = new JButton("登录");
reset = new JButton("重置");
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String name = t_name.getText();
String pass = new String(t_pass.getPassword());
if("admin".equals(name) && "admin".equals(pass)){
JOptionPane.showMessageDialog(null,"欢迎 "+name+" 登录!","提示",JOptionPane.INFORMATION_MESSAGE);
}else{
JOptionPane.showMessageDialog(null,"登录出现异常,请检查你的用户名和密码是否拼写正确","提示",JOptionPane.INFORMATION_MESSAGE);
}
}
});
reset.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
t_name.setText("");
t_pass.setText("");
}
});
pan = new JPanel();
pan.add(l_name);
pan.add(t_name);
pan.add(l_pass);
pan.add(t_pass);
pan.add(submit);
pan.add(reset);
pan.setSize(250,150);
setTitle("模拟用户登录");
setSize(250,150);
setLocation(200, 300);
add(pan);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new UserLogin();
}
}本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网