老师,4-8自由编程修改数据,回显数据的时候网页报错

老师,4-8自由编程修改数据,回显数据的时候网页报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<%@ 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 http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登录页面</title>
</head>
<body>
    <h3 align="center">登录页面</h3>
    <hr>
    <form action="logon_control.jsp">
        <table align="center">
            <tr>
                <td>用户名</td>
                <td><input type="text" name="account"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" name="password"></td>
            </tr>
            <tr>
                <td><input type="submit" value="登录"/></td>
            </tr>
        </table>
    </form>
</body>
</html>
 
 
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="com.imooc.test.*,com.imooc.test1.*,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=utf-8">
<title>登录处理</title>
</head>
<body>
 
    <%
        String account=request.getParameter("account");
        String password=request.getParameter("password");
        Notice no=new Notice(account,password,null,null);
        boolean flag=DBNotice.Judge(no);
        Map<String,Notice> map=DBNotice.map;
        if(flag==true){
    %>
        <h3 align="center">公告列表为</h3>
        <br>
        <hr>
        <br>
        <br>
        <form action="select.jsp">
        <table align="center" border="1" width="500px" cellspacing="0">
            <tr>
                <td>公告编号</td>
                <td><input type="text" placeholder="null" name="account"/></td>
                <td><input type="submit" value="select" /></td>
            </tr>
        </table>
        </form>
        <table align="center" border="1" width="500px" cellspacing="0">
            <tr>
                <td>编号</td>
                <td>名称</td>
                <td>内容</td>
                <td>删除</td>
                <td>修改</td>
            </tr>
            <tr>
                <%
                    for(String key:map.keySet()){
                        Notice no1=map.get(key);
                %>
                    <tr>
                        <td><%=no1.getAccount() %></td>
                        <td><%=no1.getName() %></td>
                        <td><%=no1.getContent() %></td>
                        <td><a href="">删除</a></td>
                        <td><a href="update.jsp?account=<%=no1.getAccount()%>&name=<%=no1.getName()%>&content=<%=no1.getContent()%>">修改</a></td>
                    </tr>
                <%  
                    }
                %>          
            </tr>
        </table>
    <%
                 
        }else{
            out.println("登录失败");
        }
    %>
</body>
</html>
 
 
<%@ 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 http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>修改页面</title>
</head>
<body>
    <form action="">
        <table>
            <tr>
                <td>编号:</td>
                <td><input type="text" value="<%=request.getParameter("account") %>" /></td>
            </tr>
            <tr>
                <td>标题:</td>
                <td><input type="text" value="<%=request.getParameter("name") %>"/></td>
            </tr>
            <tr>
                <td>内容:</td>
                <td><input type="text" value="<%=request.getParameter("content") %>"/></td>
            </tr>
            <tr>
                <td><input type="submit" value="修改"/></td>
            </tr>
        </table>
     
    </form>
</body>
</html>


正在回答

登陆购买课程后可参与讨论,去登陆

4回答

如下图所示,查询数据时,并没有出现你截图中的报错信息。而标题和内容都是null值,

http://img1.sycdn.imooc.com//climg/5ba0d66600015d3b04120172.jpg

修改建议,你可以在select.jsp中修改一下代码,请同学参考如下代码与自己代码进行核对,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="com.imooc.test.*,com.imooc.test1.*,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=utf-8">
<title>修改页面</title>
</head>
<body>
    <form action="">
        <table>
            <tr>
                <td>编号:</td>
                <td><input type="text" value="<%=request.getParameter("account") %>" /></td>
            </tr>
            <tr>
                <td>标题:</td>
                <td><input type="text" value="<%=DBNotice.map.get(request.getParameter("account")).getName() %>"/></td>
            </tr>
            <tr>
                <td>内容:</td>
                <td><input type="text" value="<%=DBNotice.map.get(request.getParameter("account")).getContent() %>"/></td>
            </tr>
            <tr>
                <td><input type="submit" value="修改"/></td>
            </tr>
        </table>
      
    </form>
</body>
</html>

修订之后的效果如下图,如有问题,可以继续提问,祝学习愉快~

http://img1.sycdn.imooc.com//climg/5ba0d6fd00015a5d02650166.jpg

提问者 指尖板命狂敲 2018-09-18 18:26:08
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.imooc.test;
 
public class Notice {
    private String account;
    private String password;
    private String name;
    private String content;
    public Notice(String account, String password, String name, String content) {
        this.account = account;
        this.password = password;
        this.name = name;
        this.content = content;
    }
    public String getAccount() {
        return account;
    }
    public void setAccount(String account) {
        this.account = account;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
     
}




package com.imooc.test1;


import java.util.HashMap;

import java.util.Map;


import com.imooc.test.Notice;


public class DBNotice {

public static Map<String,Notice> map=new HashMap();

static {

map.put("101", new Notice("101", "123456","开学", "请同学们于9月1日前来报到"));

map.put("102", new Notice("102", "123456","选课", "开始选课啦~~"));

map.put("103", new Notice("103", "123456","竞选班委", "将于近期竞选班干部"));

map.put("104", new Notice("104", "123456","评选奖学金", "评选奖学金啦~~"));

}


//判断用户名和密码是否正确

public static boolean Judge(Notice no) {

boolean flag=false;

for(String key:map.keySet()) {

Notice no1=map.get(key);

if(no.getAccount().equals(no1.getAccount())&&no.getPassword().equals(no1.getPassword())) {

flag=true;

break;

}

}

return flag;

}

}


提问者 指尖板命狂敲 2018-09-18 12:46:57
  • 根据你贴的代码,无法发现问题所在,建议你将DBUtil和Notice类中的代码也粘贴一下,方便老师进行调试,祝学习愉快~
    2018-09-18 18:11:05
  • 提问者 指尖板命狂敲 回复 chrismorgen #2
    麻烦老师看一下 我把map里面的value值改成数值型就可以通过URL传过去,改成文字就不行。
    2018-09-18 18:28:56
chrismorgen 2018-09-18 12:02:22

建议同学把你的报错提示也粘贴出来,方便老师更准确的帮你定位问题并解答,祝学习愉快~

  • 提问者 指尖板命狂敲 #1
    报错我贴出来。麻烦老师帮我看下
    2018-09-18 12:47:47
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
从网页搭建入门Java Web2018版
  • 参与学习           人
  • 提交作业       1088    份
  • 解答问题       10204    个

如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码