一个简陋的留言板

【效果图】


就两个jsp文件搞定
example2_1.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>留言板</title>
		<style>
			.userinput{
				width:100px;
			}
		</style>
	</head>
	<body>
		<form action="sub.jsp" method="post">
			Name: &nbsp; <input class="userinput" type="text" name="user" /><br>
			Content:<br/>
			<textarea value="" name="newwords" cols="20" rows="3">
			</textarea>
			<br>
			<input type="submit" value="submit"/>
		</form>
		<br>
		<a href="sub.jsp">view comments</a>
	</body>
</html>

sub.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>example3_1</title>
	</head>
	<body>
		<%
			request.setCharacterEncoding("utf-8");
			if (application.getAttribute("mainboard")==null){
				application.setAttribute("mainboard", "");
			}
			String cur = (String)application.getAttribute("mainboard");
			if (!(request.getParameter("user")==null) &&
					!(request.getParameter("newwords")==null)){
				String user = request.getParameter("user");
				String words = request.getParameter("newwords");

				if (cur.length()!=0){
					cur = cur + "<br>";
				}
				cur = cur + user+":";
				cur = cur + words;
				application.setAttribute("mainboard", cur);
			}
			out.print(cur);
		%> 
		<br><br>
		<a href="example2_1.jsp">返回</a>
	</body>
</html>
posted @ 2020-01-07 19:31  AWCXV  阅读(...)  评论(...编辑  收藏