留言板(application)

用application制作简单留言板

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>留言板</title>
</head>
<body>

<form action="55555.jsp" method="post">
<table>
<tr>
<td>昵称:</td>
<td><input type="text" name="name"/></td>
</tr>
<tr>
<td>邮箱:</td>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td>留言内容:</td>
</tr>
</table>
<table>
<tr>
<td><textarea  name="liuyan" rows="20" cols="60"></textarea></td>
</tr>
</table>


<table>
<tr>
<td><input type="submit" value="提交"/></td>
<td><input type="reset"/></td>
</tr>


</table>

</form>





</body>
</html>

处理界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% 
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
String email=request.getParameter("email");
String liuyan=new String(request.getParameter("liuyan").getBytes("ISO-8859-1"),"UTF-8");
if(name==""||email==""||liuyan=="")
{
    out.print("请把内容补充完整,5秒后跳转到留言界面");
    response.setHeader("refresh", "5;appliuyan.jsp");
    
    }
else
{
String s="姓名:"+name+"<br>邮箱:"+email+"<br>留言内容:"+liuyan+"<br>";
String message1=(String)application.getAttribute("message");
if(message1==null)
{
    application.setAttribute("message", s);
}
else
{
    
    message1+=s;
    application.setAttribute("message", message1);
    
}
out.print("留言提交成功!");
}

%>

<form action="66666.jsp">

<table>
<tr><td>查看其它留言</td></tr>
<tr><td><input type="submit" value="查看"/></td></tr>


</table>


</form>





</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<%
String str=(String)application.getAttribute("message");
out.print(str);

%>
<a href="appliuyan.jsp">继续留言</a>

</body>
</html>

运行结果:

posted @ 2016-07-01 08:40  鱼在我这里  阅读(506)  评论(0编辑  收藏  举报