i 绝望

依然

Miss Lang

java web 程序---留言板

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

一个页面显示留言内容。用到Vector来存取信息并显示

 

cas.jsp

<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

 <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>

  

posted on 2014-05-15 13:17  juewang  阅读(2036)  评论(0编辑  收藏  举报

绝望依然

Miss Lang