日期:2014-05-17 浏览次数:20744 次
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%> <%@ page import="java.util.*;" %> <html> <head> <title>留言板</title> </head> <body> <%! Vector<String> v = new Vector<String>(); int i = 0; ServletContext application; synchronized void sendMessage(String s) { application = getServletContext(); i++; v.add("NO." + i + " " + s); application.setAttribute("Mess", v); } %> <% String name = request.getParameter("peopleName"); String title = request.getParameter("title"); String message = request.getParameter("message"); if(name == null ) { name = "guest" + (int)(Math.random()*1000); } if(title==null) { title ="noe title"; } if(message==null) { message="no message"; } String s = "<br>[color=#FFFF00] 姓名[/color]: " + name + "#" + "[color=#FFFF00]标题: [/color]" + title + "#" + "[color=#FFFF00]内容[/color]: " + "<br>" + message; sendMessage(s); out.println("你的信息已经提交!!"); %> <a href="submit.jsp">返回</a> <br> <form action="showMessage.jsp"method="post"name="form1"> <input type="submit"name="look"value=" 查看留言 板 "> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%> <%request.setCharacterEncoding("GB2312");%> <%@ page import="java.util.*;" %> <html> <head> <title>留言板</title> </head> <body> <% Vector<String> v = (Vector)application.getAttribute("Mess"); for(int i = 0; i<v.size();i++) { String message = (String)v.elementAt(i); StringTokenizer fenxi = new StringTokenizer(message,"#"); while(fenxi.hasMoreTokens()) { String str = fenxi.nextToken(); byte a[] = str.getBytes("ISO-8859-1"); str = new String(a); out.println("<br>" + str); } } %> </body> </html>