index.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2019/5/7 0007
Time: 下午 4:54
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<%
if(session.getAttribute("message")!=null){
out.println(session.getAttribute("message").toString());
}
%>
<form action = "deal.jsp" method = "post" name = "form1" onsubmit="checkNull(form1)">
<table>
<tr>
<td>留言人</td>
<td><input type = "text" name = "author" id = "authId" title = "留言人"></td>
</tr>
<tr>
<td>留言内容</td>
<td> <textarea rows = "10" cols = "40" name = "content" id=“content"> </textarea></td>
</tr>
<tr>
<td colspan = "2" align = "center">
<input type = "submit" name = "submit1" value = "写留言">
<input type = "reset" name = "submit2" value = "重置">
</tr>
</table>
</form>
<%@ include file ="bootom.jsp"%>
<script type = "text/javascript">
function checkNull(form) {
for(i = 0;i<form.length;i++){
if(form.elements[i].value==""){
alert("抱歉"+form.elements[i].title+"不能为空");
form.elements[i].focus();
return false;
}
}
}
</script>
<img src="bottom.jpg">
</body>
</html>
deal.jsp
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2019/5/8 0008
Time: 上午 10:31
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String author = request.getParameter("author");//获取留言人
String content= request.getParameter("content");//获取留言内容
String message = "["+author+"]说:"+content+"<br/>";//组合得到message
if(session.getAttribute("massage")!=null){
message+=session.getAttribute("message").toString();
}
session.setAttribute("message",message);//存入session
response.sendRedirect("index.jsp");//重定向index.jsp页面
%>
</body>
</html>