Copy codeThe Code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8"
PageEncoding = "UTF-8" %>
<% @ Page import = "java. io. BufferedReader" %>
<% @ Page import = "net. sf. json. *" %>
<%
BufferedReader in = request. getReader ();
StringBuffer jsonStr = new StringBuffer ();
String str = "";
While (str = in. readLine ())! = Null ){
JsonStr. append (str );
}
JSONObject jsonObj = JSONObject. fromObject (jsonStr. toString ());
String name = jsonObj. getString ("userName ");
String pwd = jsonObj. getString ("passWord ");
String msg = "";
If (name. equals ("Tom ")){
Msg = "Logon successful ";
} Else
{
Msg = "Logon Failed ";
}
Response. getWriter (). write (msg );
%>
The process of receiving JSON data.
Required data packets:
1. commons-lang.jar
2. commons-beanutils.jar
3. commons-collections.jar
4. commons-logging.jar
5. ezmorph. jar
6. json-lib-2.2.2-jdk15.jar
Otherwise, JSONObject reports an error and cannot receive the error.