We just need to write a servlet at this point:
public class Updatemenuservlet extends HttpServlet {
/**
*
*/
Private static final long serialversionuid = 1L;
Construction method
Public Updatemenuservlet () {
Super ();
}
Method of Destruction
public void Destroy () {
Super.destroy ();
}
Responding to a GET request
public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
Response.setcontenttype ("Text/xml");
PrintWriter out = Response.getwriter ();
Instantiate DAO
Updatedao dao = new Updatedaoimpl ();
Get a list of recipes
list<menu> list = Dao.getmenulist ();
Spelling XML Format data
Out.println ("<?xml version= ' 1.0 ' encoding= ' UTF-8 '?>");
Root node
Out.println ("<menulist>");
for (int i = 0; I <list.size (); i++) {
Menu m = List.get (i);
Out.println ("<menu>");
Recipe number
Out.print ("<id>");
Out.print (M.getid ());
Out.println ("</id>");
Classification
Out.print ("<typeId>");
Out.print (M.gettypeid ());
Out.println ("</typeId>");
Name
Out.print ("<name>");
Out.print (M.getname ());
Out.println ("</name>");
Picture path
Out.print ("<pic>");
Out.print (M.getpic ());
Out.println ("</pic>");
Price
Out.print ("<price>");
Out.print (M.getprice ());
Out.println ("</price>");
Note
Out.print ("<remark>");
Out.print (M.getremark ());
Out.println ("</remark>");
Out.println ("</menu>");
}
Out.println ("</menulist>");
Out.flush ();
Out.close ();
}
Responding to post requests
public void DoPost (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
Doget (Request,response);
}
Initialize method
public void Init () throws Servletexception {
}
}
Then just enter the URL of the servlet directly into the browser.
<?xml version= "1.0" encoding= "UTF-8"?>
-<menulist>
-<menu>
<id>1</id>
<typeId>1</typeId>
<name> Water boiled fish </name>
<pic>test</pic>
<price>20</price>
<remark>test</remark>
</menu>
-<menu>
<id>2</id>
<typeId>2</typeId>
<name> Tomato Salad </name>
<pic>tets</pic>
<price>10</price>
<remark>test</remark>
</menu>
-<menu>
<id>3</id>
<typeId>3</typeId>
<name>tofu</name>
<pic>test</pic>
<price>8</price>
<remark>test</remark>
</menu>
</menulist>
The Android Development server accesses the MySQL database and parses a table in the database into XML format to output to the browser