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

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日

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?