servlet向jsp传值,jsp怎么都取不出来,

为什么我传不过去值,前端取出来一直是null

img

img

img

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录页面-学生成绩管理系统-java web实战</title>
    <style>
        #cont div {
            text-align: center;
            padding: 15px;
        }
        #cont div:last-child input:first-child {
            margin-right: 30px;
        }
        #cont div:last-child input:last-child {
            margin-left: 30px;
        }
    </style>
</head>
<body>
<div style="margin-top: 150px">
    <jsp:include page="top.jsp"/>
    <div id="cont">
        <%
            String message = (String) request.getAttribute("message");
            out.print(message);
            if (message != null) {
        %>
        <h3 style="color: #ff0000;text-align: center">出错信息:${message}</h3>
        <%
            }
        %>
        <form action="<%= request.getContextPath()%>/account?method=login" method="post">
            <div>
                <label for="userName">
                    用户名:
                </label>
                <input type="text" name="userName" id="userName"/>
            </div>
            <div>
                <label>
                    &nbsp;&nbsp;密码:
                    <input type="password" name="pwd"/>
                </label>
            </div>
            <div>
                <input type="submit" value="登录"/>
                <input type="button" onclick="resetForm()" value="重置"/>
            </div>
        </form>
    </div>
    <jsp:include page="bottom.jsp"/>
</div>
<script>
    function resetForm() {
        document.forms[0].reset();
    }
</script>
</body>
</html>



在jsp页面顶部先赋值看下,能显示就说明是servlet没有设置上值
<%
request.setAttribute("message",new Date()); //添加一个属性
%>

<%

     request.setAttribute("message",new Date());
        String message = (String) request.getAttribute("message");
        out.print(message);
        if (message != null) {
    %>
    <h3 style="color: #ff0000;text-align: center">出错信息:${message}</h3>
    <%
        }
    %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录页面-学生成绩管理系统-java web实战</title>
    <style>
        #cont div {
            text-align: center;
            padding: 15px;
        }
        #cont div:last-child input:first-child {
            margin-right: 30px;
        }
        #cont div:last-child input:last-child {
            margin-left: 30px;
        }
    </style>
</head>
<body>
<div style="margin-top: 150px">
    <jsp:include page="top.jsp"/>
    <div id="cont">
       
        <h3 style="color: #ff0000;text-align: center">出错信息:<%=message%></h3>
      
        <form action="<%= request.getContextPath()%>/account?method=login" method="post">
            <div>
                <label for="userName">
                    用户名:
                </label>
                <input type="text" name="userName" id="userName"/>
            </div>
            <div>
                <label>
                    &nbsp;&nbsp;密码:
                    <input type="password" name="pwd"/>
                </label>
            </div>
            <div>
                <input type="submit" value="登录"/>
                <input type="button" onclick="resetForm()" value="重置"/>
            </div>
        </form>
    </div>
    <jsp:include page="bottom.jsp"/>
</div>
<script>
    function resetForm() {
        document.forms[0].reset();
    }
</script>
</body>
</html>

在doGet方法中resp对象后添加一个Model对象,使用model对象赋值,然后前端仍用你现有的写法试试
model.addAttribute("message", "用户名不存在");