The Android Development server accesses the MySQL database and parses a table in the database into XML format to output to the browser

Source: Internet
Author: User

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

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.