用application对象,实现添加留言和显示留言功能(练习)

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <%
11 application.removeAttribute("name1");
12 Object obj=application.getAttribute("name1");
13 if(obj!=null)
14 {
15     String str=obj.toString();
16 %>
17 <form action="text2.jsp" method="post">
18 <textarea rows="10" cols="50" name="name"><%=str %></textarea>
19 <br>
20 <input type="submit" value="提交">
21 </form>
22 <%} %>
23 <%
24 if(obj==null)
25 {
26     %>
27     <form action="text2.jsp" method="post">
28     <textarea rows="10" cols="50" name="name"></textarea>
29     <br>
30     <input type="submit" value="提交">
31 <%} %>
32 </body>
33 </html>
 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <%
11 
12 String str1= new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
13 application.setAttribute("name", str1);
14 Object obj=application.getAttribute("name").toString();
15 %>
16 
17 <textarea rows="10" cols="50" name="name1"><%="你的留言内容是:"+obj %></textarea>
18 
19 <a href="text1.jsp">继续留言</a>
20 <%
21 application.setAttribute("name1", obj);
22 %>
23 </body>
24 </html>

 

posted @ 2016-06-30 22:40  明天会更好!!!!  阅读(411)  评论(0)    收藏  举报