JSP uses Application object to make message board

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.