I need to send a HTTP GET/POST request to an external API which returns XML data and then parse this data. Does an API for this exist in JSP?
If I use that code inside a class and use a method of it in JSP, will there be any problems?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
URLConnectionto send a HTTP request and get the HTTP response as anInputStream. You can use JAXB to unmarshal anInputStreamcontaining a XML document into a javabean instance which follows the XML structure.Imagine that the XML response look like this,
and your JAXB javabean look like this,
then you can unmarshal it something like as follows:
As with every other line of Java code in JSP, doing this in a JSP file instead of a normal Java class doesn’t necessarily cause technical problems, but it may end up in maintenance nightmare.