tags:

views:

66

answers:

4

This [servlet or jsp] must return an XML document [for future processing by my web-app]. That is not intended for end-users.

What is a better design: write a JSP or an XML ?

p.s. What I don't like about jsp is that every system admin can see your java code.

p.p.s If that'd be a jsp, than it must be capable to be autowired by Spring. Is it as easy to do as with servlets?

A: 

I think that must be a Servlet.

In my case it has to make DB calls, extract data, process it.

That is not a kind of operations a JSP is to do.

EugeneP
JSP is quite capable of doing those things.
David Dorward
@David Dorward yes, 'cause basically jsp )
EugeneP
+2  A: 

Generally speaking, XML documents should be generated using a proper XML tool chain and not a template. This strongly suggests using a servlet since the primary advantage of JSP is that it is template orientated.

David Dorward
+2  A: 

JSP's generate characters, servlets bytes. For XML character encodings to work correctly you need bytes, hence servlets.

Thorbjørn Ravn Andersen
+1  A: 

I would use a servlet for this in combination with a Javabean-to-XML serializer, such as XStream, XMLBeans, etc.

XStream is pretty easy:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Person person = personDAO.find(request.getParameter("personId"));
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    new XStream().toXML(person, response.getWriter());
}

No need to hassle with template text, so also no need for JSP.

BalusC