标签:input tchar nbsp enc etc method submit 留言板 ram
【效果图】
就两个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: <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>
标签:input tchar nbsp enc etc method submit 留言板 ram
原文地址:https://www.cnblogs.com/AWCXV/p/12163341.html