首页 > 编程语言 > 详细

java web 程序---留言板

时间:2014-05-15 18:01:15      阅读:442      评论:0      收藏:0      [点我收藏+]

思路:一个form表单,用户提交留言

一个bubuko.com,布布扣页面显示留言内容。用到Vector来存取信息并显示

 

cas.jsp

1
2
3
4
5
6
7
8
9
10
<body>
    <form action="fei.jsp">
         留言人: <input type="text" name="name"/><br/>
        标题:<input type="text" name="title"/><br/>
        留言内容:<br/>
        <textarea rows="6" cols="40" name="message"></textarea>
        <br/>
        <input type="submit" value="提交"/>
    </form>
  </body>

  fei.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<body>
   <%
       String name=request.getParameter("name");
       String a=new String(name.getBytes("ISO-8859-1"),"gb2312");
       String title=request.getParameter("title");
       String b=new String(title.getBytes("ISO-8859-1"),"gb2312");
       String message=request.getParameter("message");
       String c=new String(message.getBytes("ISO-8859-1"),"gb2312");
       Vector v=(Vector)application.getAttribute("v");   
           if(v==null){
               v=new Vector();
        
       }
           String time=(new Date()).toLocaleString();
           String s=a+"#"+b+"#"+c+"#"+time;//这里的”#“符号不能多写,否则会多出一列来
     
           v.add(s);
           application.setAttribute("v",v);
           if(name==null||name.equals("")){
           name="guess"+(int)(Math.random()*1000);
       }
           out.print("<table border=‘1‘>");
           out.print("<tr><th>留言人</th><th>标题</th><th>留言内容</th><th>留言时间</th></tr>");
           for(int i=0;i<v.size();i++){
               out.print("<tr>");
               String st=(String)v.elementAt(i);
                   String ss[]=    st.split("#");
                       for(int j=0;j<ss.length;j++){
                        
                           out.print("<td>"+ss[j]+"</td>");
                                
                       }
                       out.print("</tr>");
           }
    %>
 </body>

  

java web 程序---留言板,布布扣,bubuko.com

java web 程序---留言板

原文:http://www.cnblogs.com/langlove/p/3729814.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!