chauncy_win 2022-07-03 19:05 采纳率: 90%
浏览 102
已结题

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>



  • 写回答

3条回答 默认 最新

  • bug_keng 2022-07-03 19:57
    关注

    在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>
        <%
            }
        %>
    
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 7月4日
  • 创建了问题 7月3日