1<%@ page contenttype="text/html; charset=gb2312"%>23<body>4<form action="show.jsp"Method="Post">5Input name: <input type="text"Name="name"><br> Message title:<input6Type="text"Name="title"><br> message:<br>7<textarea rows="Ten"cols=" -"Name="text"wrap="Physical"></textarea>8<br> <input type="Submit"Value="Submit"><br>9</form>Ten<form action="chuli.jsp"Method="Get"> One<input type="Submit"Name=" Look"Value="View Message Board"><br> A</form> - - the</body> -
<%@ page contenttype="text/html; charset=gb2312"%><% @page import="Java.util.Vector"%><%@ page import="java.util. *"%><%request.setcharacterencoding ("gb2312"); String name= Request.getparameter ("name"); String title= Request.getparameter ("title"); String text= Request.getparameter ("text"); if(Name = =NULL|| Name.length () = =0) name=""; if(title = =NULL|| Title.length () = =0) Title=""; if(Text = =NULL|| Text.length () = =0) Text=""; String s= name +"#"+ title +"#"+text; Add (s);%><%! Vector vector =NewVector (); ServletContext Application; //Some servers do not directly support application objects.//This object must be declared with the ServletContext class class,//then use the Getservletcontext method//initializing the Application object inti =0; SynchronizedvoidAdd (String s) {application=Getservletcontext (); I++; Vector.add ("NO."+ i +","+s); Application.setattribute ("mess", vector);//If you add 2 objects with the same keyword, the previous keyword is cleared, mess is called the index keyword}%><a href="chuli.jsp"> Return to Message Screen </a>
<%@ page contenttype="text/html; charset=gb2312"%><%@ page import="Java.util.Vector"%><%! Publicstring handstring (string s) {Try { byteB[] = s.getbytes ("gb2312"); S=NewString (b); } Catch(Exception exp) {}returns; }%><%vector Vector= (Vector) Application.getattribute ("mess"); //because any object can be added to the application, when the object is retrieved,//so you have to force it back to the original type. for(inti =0; I < vector.size (); i++) { //the length of the vector is vector.size ();String message =(String) vector.elementat (i); //Vector is a place to put data. ElementAt (i) is the role of data extractionString str[] = Message.split ("#"); out. Print ("Message Person:"+ handstring (str[0]) +";"); out. Print ("Title:"+ handstring (str[1]) +"<br>"); out. Print ("Message content:"+"<br>"+ handstring (str[2])); }%><a href="input.jsp"> Back to main interface </a>
JSP uses Application object to make message board