几乎相同的 deal.jsp 代码(index.jsp不变),在IDEA相同项目运行,结果却不一样,实在想不出来...

主要问题

几乎相同的 deal.jsp 代码(index.jsp不变),在IDEA相同项目相互运行,结果却不一样,实在想不出来

主要项目

对应的IDEA JSP项目:6.9_2.zip

index.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>显示历史、显示添加留言功能</title>
    <link rel="stylesheet" type="text/css" href="word_index.css" />

    <script language="JavaScript">
        function ifNull(form_Msg){
            var userName = form_Msg.upload_UserName.value;
            var userMsg = form_Msg.upload_UserMsg.value;
            if (userName === "") {
                alert("留言人不能为空");
                form_Msg.upload_UserName.focus();
                return false;
            }
            if (userMsg === "") {
                alert("留言内容不能为空");
                form_Msg.upload_UserMsg.focus();
                return false;
            }
        }
    </script>
</head>
<body>
<span class="word_Msg">留言板</span><br><br>
<%

    if (session.isNew()){
        int number_person_index = 0;
        session.setAttribute("number_person",number_person_index);
    }

    int i;
    String[] message_index = (String[])session.getAttribute("message");
    int num = Integer.parseInt(session.getAttribute("number_person").toString());
    if (num != 0) {
        out.println("123213132");
        out.println("number_person: " + num + "<br><br>");
        for (i=0; i < num; i++) {
            out.println(message_index[i]);
        }
    }
%>
<br><hr>

<form action="deal.jsp" id="form_UploadMassage" name="form_UploadMassage" method="post" onSubmit="return ifNull(form_UploadMassage)">
    <span class="word_Msg">添加留言区域</span><br>
    留言人:<input type="text" id="upload_UserName" name="upload_UserName" title="留言人">
    留言内容:<textarea id="upload_UserMsg" name="upload_UserMsg" title="留言内容"></textarea>
    <input name="Submit" type="submit" value="提交留言">
    <input name="Submit2" type="reset" value="重置">
</form>
</body>
</html>

deal.jsp(正确可运行):

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%
    request.setCharacterEncoding("utf-8");
    String userName_deal=request.getParameter("upload_UserName");   //获取留言人
    String userMsg_deal=request.getParameter("upload_UserMsg"); //获取留言内容
    String message_add="["+userName_deal+"]说:"+userMsg_deal+"<br>"; //组合留言信息

    int i;
    int num = Integer.parseInt(session.getAttribute("number_person").toString());
    int num_add = num+1;
    String[] message_old = (String[])session.getAttribute("message");
    String[] message_new = new String[num_add+1];

    if(session.getAttribute("number_person")!=null){
        if (num > 0) {
            for (i=0; i<num; i++) {
                message_new[i] = message_old[i];
            }
        }
        message_new[num_add-1] = message_add;
    }
    session.setAttribute("number_person",num_add);
    session.setAttribute("message",message_new);    //将留言信息保存到session中
    response.sendRedirect("index.jsp");
%>

deal.jsp(错误不可运行):

<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%
    request.setCharacterEncoding("utf-8");
    String userName_deal = request.getParameter("upload_UserName");
    String userMsg_deal = request.getParameter("upload_UserMsg");
    String message_add = "["+userName_deal+"]说:"+userMsg_deal+"<br>";   //组合留言信息

    int i;
    int num = Integer.parseInt(session.getAttribute("number_person").toString());
    int num_add = num+1;
    String[] message_old = (String[])session.getAttribute("message");
    String[] message_new = new String[num_add+1];

    if (session.getAttribute("number_person")!=null) {
        if (num > 0) {
            for (i=0; i<num; i++) {
                message_new[i] = message_old[i];
            }
        }
        message_new[num_add-1] = message_add;
    }
    session.setAttribute("number_person",num_add);
    session.setAttribute("massage",message_new);
    response.sendRedirect("index.jsp");
%>

错误的代码运行图片:

1591904-20190906205534372-228999126.png
1591904-20190906205549443-650104332.png

可运行的代码运行图片

1591904-20190906205627468-964018525.png
1591904-20190906205636527-1065399242.png

转载于:https://www.cnblogs.com/Yogile/p/11477952.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值