EugeneP
EugeneP

Reputation: 12003

Easy way to write servlet that returns table data in xml format

Easy way to write servlet that returns table data in xml format - ?

Data comes from a database table.

Upvotes: 1

Views: 3729

Answers (2)

Qwerky
Qwerky

Reputation: 18445

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TableServlet extends HttpServlet
{
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        response.setContentType("application/xml");
        PrintWriter writer = response.getWriter();
        writer.println("<?xml version=\"1.0\"?>");
        writer.println("<table>");
        writer.println("<style>");
        writer.println("<finish>polished</finish>");
        writer.println("<material>oak</material>");
        writer.println("</style>");
        writer.println("<legs>4</legs>");
        writer.println("</table>");
        writer.flush();
    }
}

Upvotes: 3

ahvargas
ahvargas

Reputation: 902

You may found jersey useful it works for XML, also supports JSON . Here is a good tutorial (Look section 4) .

Upvotes: 2

Related Questions