日期:2014-05-17  浏览次数:20784 次

jsp简单的留言板 求助··

submit.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>留言板</title>
</head>

<body>
<h3>留言页面</h3>
<form action="messagepane.jsp" method="post" id="myform">
输入姓名:
<input type="text" name="name" value="">
</br>
输入留言标题:
<input type="text" name="title" value="" >
</br>
输入留言: 
<textarea name="mess" rows="10" cols="30" wrap="physical">
</textarea>
</br>
<input type="submit" name="submit" value="提交" >
</br></br>
</form>

<form action="messageshow.jsp" method="post" >
<input type="button" name="info" value="查看留言板" >
</form>
</body>
</html>


messagepane.jsp

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*" errorPage="" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<%! 
 Vector v=new Vector();
synchronized void sendmess(String s){
  ServletContext application=getServletContext();
  v.add(s);
 application.setAttribute("mess",v);
}
%>
<%
 String name=request.getParameter("name");
 String title =request.getParameter("title");
 String mess=request.getParameter("mess");
 if(name==""){
  name="guest"+(int)Math.random()*10000;
 }
 if(title==""){
 title="无标题";
 }
 if(mess==""){
 title="无信息";
 }
 String str="Name:"+name+"Title:"+title+"Content:"+"<br>"+mess;
 sendmess(str);
 out.print("您的信息已提交");
%>

<a href="submit.jsp">返回</a>
</body>
</html>


messageshow.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*" errorPage="" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<%
 Vector v=(Vector)application.getAttribute("mess");
 for(int i=0;i<v.size();i++){
   String message=(String)v.elementAt(i);
    out.print(message+"<br/>");
 }
%>
</body>
</html>

点击查看留言板 没反应 错在哪?