[toc]
主要问题
几乎相同的 deal.jsp 代码(index.jsp不变),在IDEA相同项目相互运行,结果却不一样,实在想不出来
主要项目
index.jsp:
显示历史、显示添加留言功能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;
}
}
留言板
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 + "
");
for (i=0; i < num; i++) {
out.println(message_index[i]);
}
}
%>
添加留言区域
留言人:
留言内容:
deal.jsp(正确可运行):
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+"
";//组合留言信息
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
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(错误不可运行):
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+"
";//组合留言信息
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
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");
%>
错误的代码运行图片:
可运行的代码运行图片