访问量和要修改的值都为null啊
package RS;
import java.util.HashMap;
import java.util.Map;
public class BDUtil {
public static Map<String, User> map = new HashMap<String, User>();
static {
map.put("101", new User("101","AA","123456","AA@qq.com"));
map.put("102", new User("102","BB","123456","BB@qq.com"));
map.put("103", new User("103","CC","123456","CC@qq.com"));
map.put("104", new User("104","DD","123456","DD@qq.com"));
}
//判断用户名密码是否正确
public static boolean PD(User user) {
boolean flag = false;
for (String key : map.keySet()) {
User u = map.get(key);
if (user.getAccount().equals(u.getAccount()) && user.getPassword().equals(u.getPassword())) {
flag = true;
}
}
return flag;
}
}<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta>
<title>Insert title here</title>
</head>
<body>
<%
//request.setAttribute("name", "imooc");
//request.getRequestDispatcher("result.jsp").forward(request, response);
%>
<h3>人事管理登陆页面</h3>
<!-- <h4>登陆账号为:<%=session.getAttribute("account") %></h4> -->
<hr>
<form action="control.jsp">
<table>
<tr>
<td>
账号:<input type="text" name="account"><br>
</td>
</tr>
<tr>
<td>
密码:<input type="password" name="password"><br>
</td>
</tr>
<tr>
<td>
<input type="submit" value="提交"><br>
</td>
</tr>
</table>
</form>
</body>
</html><%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="RS.*" %>
<%@page import="java.util.Map" %>
<%@page import="java.util.HashMap" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta>
<title>Insert title here</title>
</head>
<body>
<%
String aaa = request.getMethod();
String account = request.getParameter("account");
String password = request.getParameter("password");
User user = new User(account,null,password,null);
boolean flag = BDUtil.PD(user);
Map<String,User> map = BDUtil.map;
session.setAttribute("account", account);
if(flag == true){
Object o = application.getAttribute("count");
if(o == null){
application.setAttribute("conut", 1);
}else{
int count = Integer.parseInt(o.toString());
application.setAttribute("count", count + 1);
}
%>
<%=aaa %>
<h3>人事管理页面</h3>
<h4>登陆账号为:<%=session.getAttribute("account") %></h4>
<h4>访问量:<%=application.getAttribute("count") %></h4>
<table border="1">
<tr>
<td>
账号
</td>
<td>
姓名
</td>
<td>
邮箱
</td>
<td>
修改
</td>
</tr>
<%
for(String key : map.keySet()){
User u = map.get(key);
%>
<tr>
<td>
<%=
u.getAccount()
%>
</td>
<td>
<%=
u.getName()
%>
</td>
<td>
<%=
u.getEmail()
%>
</td>
<td>
<a href="update.jsp?account=<%=u.getAccount()%>
name=<%=u.getName()%>
email=<%=u.getEmail()%>">修改</a>
</td>
</tr>
<%
}
%>
</table>
<%
}else{
out.print("用户密码不正确");
}
%>
</body>
</html>
正在回答
点击修改的链接传递的参数中间加一个&:<a href="update.jsp?account=<%=u.getAccount()%>&name=<%=u.getName()%>&email=<%=u.getEmail()%>">修改</a>
另外,你在update.jsp中,需要获取到这三项的值,然后写到input框内。
祝学习愉快!
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10205 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星