修改功能时emp取值为null,无法修改,请帮忙看看,谢谢
javabean:Emp类
package com.imooc.bean;
public class Emp {
private String account;
private String name;
private String password;
private String email;
//无参构造方法
public Emp() {
}
//带参构造方法
public Emp(String account, String name, String password, String email) {
this.setAccount(account);
this.setName(name);
this.setPassword(password);
this.setEmail(email);
}
//get&set方法
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}DBUtil类:
package com.imooc.db;
import com.imooc.bean.Emp;
import java.util.HashMap;
import java.util.Map;
public class DBUtil {
public static Map<String, Emp> map = new HashMap<String, Emp>();
static {
map.put("1001", new Emp("1001", "AA", "123456", "AA@email.com"));
map.put("1002", new Emp("1002", "BB", "123456", "BB@email.com"));
map.put("1003", new Emp("1003", "CC", "123456", "CC@email.com"));
map.put("1004", new Emp("1004", "DD", "123456", "DD@email.com"));
}
/**
* 判断用户名和密码是否正确
*/
public static boolean selectEmpByAccountAndPassword(Emp emp) {
boolean flag = false;
for (String key : map.keySet()) {
Emp e = map.get(key);
if (emp.getAccount().equals(e.getAccount()) && emp.getPassword().equals(e.getPassword())) {
flag = true;
break;
}
}
return flag;
}
}Jsp页面-update.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>员工信息更新</title>
<style>
td{
text-align: center;
background: #d0eaff;;
}
h3{
color: blue;
}
</style>
</head>
<body>
<h3 align="right">登录账号:<%=session.getAttribute("account")%></h3>
<h2 align="center">员工信息更新</h2>
<hr>
<form action="update_control.jsp">
<table align="center" width="600px">
<tr>
<td>账号:</td>
<td><input type="text" name="account" value="<%=request.getParameter("account")%>" readonly></td>
</tr>
<tr>
<td>名称:</td>
<td><input type="text" name="name" value="<%=request.getParameter("name")%>"></td>
</tr>
<tr>
<td>邮箱:</td>
<td><input type="text" name="email" value="<%=request.getParameter("email")%>"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="修改"></td>
</tr>
</table>
</form>
</body>
</html>Jsp页面-control.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" import="com.imooc.db.*,com.imooc.bean.*" errorPage="error.jsp" %>
<%@ page import="java.util.Map" %>
<html>
<head>
<title>Title</title>
<style>
td{
text-align: center;
background: #d0eaff;;
}
h3{
color: blue;
}
</style>
</head>
<body>
<%
String account = request.getParameter("account");
String password = request.getParameter("password");
Emp emp = new Emp(account,null,password,null);
boolean flag = DBUtil.selectEmpByAccountAndPassword(emp);
Map<String,Emp> map =DBUtil.map;
if (flag==true){
session.setAttribute("account",account);
session.setMaxInactiveInterval(10);
Object o = application.getAttribute("count");
if (o==null){
application.setAttribute("count",1);
}else{
int count = Integer.parseInt(o.toString());
application.setAttribute("count",count+1);
}
session.setAttribute("account",account);
%>
<h3 align="right">该页面访问量为:<%= application.getAttribute("count")%></h3>
<h3 align="right" >登录账号:<%= session.getAttribute("account")%></h3>
<h2 align="center">欢迎来到人事管理系统首页</h2>
<hr>
<table align="center" border="1" width="600px">
<tr>
<td>账号</td>
<td>员工姓名</td>
<td>员工邮箱</td>
<td>修改</td>
</tr>
<%
for (String key: map.keySet()) {
Emp e = map.get(key);
%>
<tr>
<td><%= e.getAccount() %></td>
<td><%= e.getName() %></td>
<td><%= e.getEmail() %></td>
<td>
<a href="update.jsp?account= <%= e.getAccount()%>&name=<%= e.getName() %>&email=<%= e.getEmail() %>">修改</a>
</td>
</tr>
<%
}
%>
</table>
<%
}else{
throw new Exception("账号或密码错误,登录失败,请重新输入!");
}
%>
</body>
</html>Jsp页面-update_control.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" errorPage="error.jsp"
pageEncoding="UTF-8" import="com.imooc.db.*,com.imooc.bean.*,java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
Map<String,Emp> map = DBUtil.map;
Emp emp = map.get(request.getParameter("account"));
emp.setName(request.getParameter("name"));
emp.setEmail(request.getParameter("email"));
%>
<h3 align="center">员工信息修改成功</h3>
</body>
</html>12
收起
正在回答 回答被采纳积分+1
3回答
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10204 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程


恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星