0

I have a JSP file in which I have an entity class - I want to add the user to the database. I have a REST web service with POST method that consumes application/xml. I guess, I have to parse the data to XML and invoke post method, but how to send this xml data to rest with this call ? I know only how to invoke GET methods, but how to call for example post or delete methods that needs some parameters? Thanks.

Piotr Sagalara
  • 2,247
  • 3
  • 22
  • 25

1 Answers1

1

You have two challenges: generating XML (not parsing, parsing is converting from XML, not to) and POSTing it.

The first problem is rather simple. You can use various libraries, from , through to manual crafting of XML using StringBuilder (not advised).

You can send POST in plain Java, see: Java: how to use UrlConnection to post request with authorization? There are also special libraries, like .

BTW do not: call web services, access database directly, start threads, open files... in JSP. At least use servlets and leave JSP for representation.

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674